简体   繁体   中英

Multi-Value Parameter in Microsoft SQL Server 2008

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM