这问题是什么问题?

时间:2011-03-08 08:04:55

标签: sql-server sql-server-2005

如果有任何问题,请相信此查询:

SELECT [travel], [service], [travelid], [fro_m], [t_o], [dep], [arr], [booking_closed],
[discount], [faresleeper], [rating], [seats], [s_no], 
[fare] = 
CASE 
  WHEN @date >= Cast(Convert(varchar(20),s1from,101) as datetime
    AND @date >= Cast(Convert(varchar(20),s1to,101) as datetime 
  THEN s1rate 
  ELSE fare 
END 
FROM a1_volvo WHERE  ( fro_m = @fro_m ) AND ( t_o = @t_o ) 

4 个答案:

答案 0 :(得分:3)

SELECT [travel], [service], [travelid], [fro_m], [t_o], [dep], [arr], [booking_closed],
[discount], [faresleeper], [rating], [seats], [s_no], 
[fare] = 
CASE 
  WHEN @date >= Cast(Convert(varchar(20),s1from,101) as datetime)
    AND @date >= Cast(Convert(varchar(20),s1to,101) as datetime )
  THEN s1rate 
  ELSE fare 
END 
FROM a1_volvo WHERE  ( fro_m = @fro_m ) AND ( t_o = @t_o ) 

答案 1 :(得分:1)

WHEN 语句中,不应该是

当@date > = 施展(转换(varchar(20),s1from,101)作为日期时间

AND @date < = Cast(转换(varchar(20),s1to,101)为datetime

如果是范围检查,则大于等于等于

答案 2 :(得分:1)

检查您的演员表应该强制转换(列为数据类型),并且还要考虑大于等于“> =”且小于等于“< =”正如il_guru所说的那样。 :) 看看这个......

SELECT [travel], [service], [travelid], [fro_m], [t_o], [dep], [arr],
  [booking_closed], [discount], [faresleeper], [rating], [seats], [s_no],      
  [fare] = CASE WHEN @date >= Cast(Convert(varchar(20),s1from,101) as datetime)
       AND @date <= Cast(Convert(varchar(20),s1to,101) as datetime)
       THEN s1rate ELSE fare END  
FROM a1_volvo  

-- use this where clause if fro_m and t_o are not datetime
WHERE (fro_m = @fro_m ) AND ( t_o = @t_o )

-- else use this where clause if fro_m and t_o have datetime of datatypes
WHERE ( Cast(Convert(varchar(20),fro_m,101) as datetime) = @fro_m ) 
AND (  Cast(Convert(varchar(20),t_o,101) as datetime) = @t_o )

答案 3 :(得分:0)

删除[fare] =然后重试。