SQL Query - Add condition in WHERE only IF another condition -


i want in clause

where ( i.accountid = @accountid        , case when @istest not null b.istest = @istest else 1 = 1 

but solution not work. there solution this. want add verification based on @istest value.

you want use simple boolean logic:

where    i.accountid = @accountid   ,   (@istest null or b.istest = @istest) 

if want make case solution work (just illustrative purposes - it's not idea), you'd need have case return value you'd compare - t-sql doesn't have "bool type" (bit incredibly-small-integer, doesn't have special syntax):

... , (case when @istest not null @istest else 1 end) = 1 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -