2014-07-17 90 views
0

我想多值傳遞給SQL Server中的參數的默認值2008多值參數在Microsoft SQL Server 2008

以下是我有:

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) 

給我上的錯誤然後(0,1) - 說明不正確的語法。我也嘗試用0和1附近的單引號無效。

任何建議將不勝感激。我有很多這些我需要在這個查詢中使用。

感謝, 斯科特

回答

1

你不能多值INT變量。但是,您可以有一個以int爲單位的表變量。

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) 
+0

謝謝,效果很好。 – SASUSMC