variables - SQL Server : Conditional where clause (Equal) OR (LessThan or Equal) -


where [date] <= case                        when @param = 1 convert(date, getdate())                    when @param = 2 dateadd(dd, 1, getdate()) 

the example above passes in variable @param intended filter for:

  • @param = 1 (all days less or inclduing today).
  • @param = 2 (all days less or inclduing today , tomorrow).
  • @param = 3 (today only). requires change expression.

question

in sql server, how create conditional where clause evaluates different equality?

where [date] <=  [date] =   

or put way:

how can add filter today?

try:

where      ([date] <= convert(date,getdate()) , @param = 1) or     ([date] <= dateadd(dd, 1, getdate()) , @param = 2) or     ([date] = getdate() , @param = 3) 

Comments

Popular posts from this blog

xml - Extract substrings with XSLT -

math - "ELO Rating" and how does "TSR Rating" work? -

How can do a tuple comparison in coffeescript similar to that in python? -