Link to home
Start Free TrialLog in
Avatar of CipherIS
CipherISFlag for United States of America

asked on

Check Value of @ID

I have the following code

declare @ID INT

SET @ID = (SELECT MyID
      Table1
      WHERE Field1 = '1')

if (DATALENGTH(@ID) = 0)
    BEGIN
        SET @ID = 1
        PRINT @ID
    END
else
    BEGIN
        set @ID = DATALENGTH(@ID)
        PRINT @ID
    END

I need to perform an Insert but I need to make sure that @ID does not contain a value.  How do I check?
ASKER CERTIFIED SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Datalength(int) returns 4 by the way, since it takes 4 bytes to store any int