sql server - Dynamically select a version of WHERE clause in SQL SELECT statement? -


basically, want select 1 of 2 versions of clause in sql select statement, without having duplicate 2 versions of whole select statement.

for example, specify variable @topclients, , execute following clause when @topclients = 'true':

where      cast(event_dtm date) between @start , @end     , client in ('client1','client2', 'client3') 

or execute following clause when @topclients = 'false':

where      cast(event_dtm date) between @start , @end 

how can this?

just use:

where      cast(event_dtm date) between @start , @end     , (       client in ('client1','client2', 'client3')        or @topclients = 'false'     ) 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -