If Exists return Identity else Insert...
Posted on 2006-05-21
I'm looking to check to see if a price exists and if it does, get the PriceId - otherwise I want to insert the new price and return its PriceId... I've got the following stored procedure below and I've put in a comment where I have the problem. The insert is fine - it's getting at the PriceId if one already exists that I'm stuck on...
CREATE PROCEDURE sp_Price_CreatePrice
@PriceId int OUTPUT
SELECT PriceId FROM Price
WHERE PriceAmount = @PriceAmount )
/* I want to set @PriceId to be the PriceId found in the above if exists query */
end else begin
INSERT INTO Price(PriceAmount) VALUES(@PriceAmount)
SET @PriceId = @@IDENTITY