2017-09-12 22 views
-3
declare @custid varchar(50) = null 

select * 
from Items 
where ShowItemNlyCusLoggedInWeb = case when 
             @custid = not null then 
             ShowItemNlyCusLoggedInWeb=0 or isnull 

Dies funktioniert nicht für mich.CASE when Klausel mit

+1

'@custid = nicht null' - falsch. '@custid ist nicht null '- richtig. – Sankar

+0

funktioniert immer noch nicht –

+0

Ihre Anfrage/case-Anweisung ist unvollständig. refer [case msdn] (https://docs.microsoft.com/en-us/sql/t-sql/language-elements/case-transact-sql) – Sankar

Antwort

0
declare @custid varchar(50)=null 

select * 
from Items 
where (ISNULL(ShowItemNlyCusLoggedInWeb,0) = 0 OR @custid IS NULL) 
+0

Wenn @cusid null ist Ich möchte etwas filtern, wenn nicht null Ich möchte alle Daten anzeigen –

+0

Welche Spalte werden Sie zum Filtern von Daten verwenden? Ist es noch 'ShowItemNlyCusLoggedInWeb'? @SatG_shanu –

+0

ja immer noch es ist ... wenn @cusid nicht null ist, zeige ich ShowItemNlyCusLoggedInWeb 0 Werte, wenn Cusid isnull ich 0 und 1 Werte –

0

Sie können suchen für diese

WHERE 1 = CASE WHEN @custid IS NOT NULL AND ShowItemNlyCusLoggedInWeb = 0 THEN 1 
       WHEN @custid IS NULL AND ShowItemNlyCusLoggedInWeb IN (0,1) THEN 1 
       ELSE 0 
      END