CipherIS
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Datalength(int) returns 4 by the way, since it takes 4 bytes to store any int