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

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -