0

I am trying to pass multiple values to a parameter default in SQL Server 2008.

Here is what I have:

Declare @PInactive  Int

Set @PInactive = Case When @PInactive is null Then (0 , 1) Else @PInactive End

Select
    ClientID
   ,PInactive
From
   #Client
Where
   PInactive in (@PInactive)

Gives me an error on Then (0 , 1)- stating incorrect syntax. I also tried with single quotes around the 0 and 1 to no avail.

Any suggestions would be greatly appreciated. I have many of these I need to use in this query.

Thanks, Scott

1 Answer 1

1

You can't have multi-value int variables. You can, however, have a table variable of ints.

DECLARE @PInactive TABLE (State INT);
IF NOT EXISTS (SELECT 1 FROM @PInactive) INSERT INTO @PInactive (State) VALUES (0),(1);

Select
ClientID
,PInactive
From
#Client
Where
PInactive in (SELECT State FROM @PInactive)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.