Conditional AND T-SQL Operator
I am trying to set up a stored procedure where I take a table value parameter and use it inside an IN statement to capture the results, the problem is the table value parameter may be empty, is there a way for me to conditionally insert an integer and a statement?
declare @var int
--insert @var
declare @tvp tvp
--insert stuff (or not) into @tvp
SELECT t.foo1, t.foo2, t.foo3
FROM dbo.t t
WHERE t.foo4 = @var
IF(EXIST (SELECT 1 FROM @tvp))
AND t.foo1 IN (SELECT @tvp.foo1 FROM @tvp)
this is what i'm going conceptually, any help on what is the correct way to do this?
+3
source to share