2011-12-07 15 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

変更isVerified = COALESCE(@viewPending, isVerified)の一部。

1=NULLはfalseと評価されます。

+1

'1 = NULL'は、「不明」として評価されます。 –

関連する問題