简体   繁体   English

Microsoft SQL Server 2008中的多值参数

[英]Multi-Value Parameter in Microsoft SQL Server 2008

I am trying to pass multiple values to a parameter default in SQL Server 2008. 我正在尝试将多个值传递给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. 在Then(0,1)上给我一个错误,指出语法错误。 I also tried with single quotes around the 0 and 1 to no avail. 我也尝试用0和1前后的单引号无效。

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. 您不能有多值int变量。 You can, however, have a table variable of ints. 但是,您可以将表变量设置为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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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