2011-12-07 34 views
1
ALTER PROCEDURE [dbo].[USP_ViewRegForm] 
    -- Add the parameters for the stored procedure here 
    ( @RegFormID  Numeric=null, 
     @FDate   Date=null, 
     @TDate   Date=null, 
     @viewPending  int=null 
    ) 
AS 
BEGIN 
    -- SET NOCOUNT ON added to prevent extra result sets from 
    -- interfering with SELECT statements. 
    SET NOCOUNT ON; 
    SET DATEFORMAT DMY; 
    -- View statements for procedure here 
    -- 
    If (@viewPending = 1 or @viewPending = 0 Or @viewPending is null) 
    Begin 

      SELECT 
      RegDate, 
      iRegFormID As [Registraion ID], 
      CenterName As [Center Name], 
      OwnerName As [Owner Name], 
      MobileNo As [Mobile], 
      MailID  As [EMail ID], 
      isVerified As [Verified] 
     FROM TBL_iREGFORM 
     WHERE (@FDate Is Null or RegDate <= @TDate) And 
       (@TDate is Null or RegDate >= @FDate) And 
       ((RegDate between @FDate and @TDate) OR (RegDate=convert(varchar(20),GETDATE(),103))) And 
       isVerified in (Case When @viewPending =1 Then 0 Else 1 | 0 End) 
    End 

問題是在這裏:isVerified in (Case When @viewPending =1 Then 0 Else 1 | 0 End)存儲過程出乎意料的結果不理想

如果我不是在@viewPenind值傳遞那麼它必須同時選擇1和0。但是,這僅返回一個值..

爲什麼?

Previous question

回答

2

更改WHERE部分isVerified = COALESCE(@viewPending, isVerified)

1=NULL評估爲false。

+1

'1 = NULL'評估爲'unknown'挑剔。 –