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
Post a Comment