Rouchie
asked on
Quick one - quickly setting a bit value based on exists statement
I'm trying to streamline my proc's and reduce the amount of code I have.
Given the following code that sets a bit value, is it possible to set the value of the bit variable all in one line, instead of the method used below?
DECLARE @bitValue bit
IF EXISTS (SELECT * FROM @someTableVar t1 INNER JOIN @anotherTableVar t2 ON t1.ID = t2.ID)
BEGIN
SET @bitValue = 1
END
ELSE
BEGIN
SET @bitValue = 0
END
Given the following code that sets a bit value, is it possible to set the value of the bit variable all in one line, instead of the method used below?
DECLARE @bitValue bit
IF EXISTS (SELECT * FROM @someTableVar t1 INNER JOIN @anotherTableVar t2 ON t1.ID = t2.ID)
BEGIN
SET @bitValue = 1
END
ELSE
BEGIN
SET @bitValue = 0
END
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys!
SELECT @bitValue = (SELECT count(1) FROM @someTableVar t1 INNER JOIN @anotherTableVar t2 ON t1.ID = t2.ID)