July 9, 2010 at 2:51 am
Hi Guys,
I am writing a stored procedure. My objective is to put a random number in a column of table, where the fields are null. So my column is App_ID. But the catch is, the App_ID column must have unique numbers and since I am generating numbers randomly there maybe instances when the same random number is generated. Therefore to take care of that I was using IF statement. So part of my code is below but I get an error "Invalid column name 'App_ID' ".
DECLARE @temp int
SET @temp = ABS(CAST(CAST(NEWID() AS VARBINARY) AS INT)) --This code generates a random number
IF @temp = App_ID --This is the part giving error.
BEGIN
UPDATE Event_Person_Info
SET App_ID = @temp
Where (NOT(App_ID IS NULL))
END
END
I know why I get the error, its because App_ID is a column and @temp is variable. Since I want to check if the value stored in @temp is present within the column App_ID, if not present then I will UPDATE. Can anyone please help me how can I do this check within the column App_ID. Would be great if you could modify the given code.
Thanks in Advance!
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply