如何编写此查询(如果在sql和日期)

时间:2015-09-02 06:36:11

标签: sql

如何编写查询

select MC_HOST_ADDRESS, LOCATION_TYPE , MC_LOCATION, MSG, STREET/SUBLOCATION, DURATION/( CLOSED_TIME - MC_ARRIVAL_TIME)
if  ( MC_ARRIVAL_TIME <  Start Date )  then   use Start Date  else  use End Date
where  
 MC_Object = ‘Camera’ AND
 MC_Parameter= ‘CameraFeed’ AND
(MC_ARRIVAL_TIME between Start Date and End Date)  OR
              ( CLOSED_TIME between Start Date and End Date) OR
         ( MC_ARRIVAL_TIME <=  Start Date and CLOSED_TIME >= End Date) OR
 ( MC_ARRIVAL_TIME <=  Start Date and CLOSED_TIME == NULL)enter code here`

1 个答案:

答案 0 :(得分:0)

在查询中使用CASE语句而不是IF子句。

CASE WHEN MC_ARRIVAL_TIME <  StartDate  THEN  StartDate  ELSE   EndDate END