以编程方式查找Where子句的执行路径?

时间:2014-01-27 18:16:04

标签: java sql sql-server

我正在使用sql server,我根据日期字段查询。例如,如果唯一的记录日期是 显然,2014-1-29会使用#1。

  Select * from Table
  Where 
  #1(date is between now & 90) or
  #2(date is between 90  * 180) or 
  #2(date is between 180 & 360);

他们无论如何都要找出实际执行地点的哪一部分。

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情:

Select 
   date,
   case 
    when date is between now & 90  then 'date is between now & 90'
    when date is between 90  * 180 then 'date is between 90  * 180'
    when date is between 180 & 360 then 'date is between 180 & 360'
end as [which]
from Table
  Where 
  #1(date is between now & 90) or
  #2(date is between 90  * 180) or 
  #2(date is between 180 & 360);