update kq_yjg set cq=
case
when k3104=null OR k3106=null then 0
when k3104<=convert(datetime,convert(varchar(100),k3103,24)+' 07:00:00') then
case
when k3106<=convert(datetime,convert(varchar(100),k3103,24)+' 07:00:00') then 0
when k3106>=convert(datetime,convert(varchar(100),k3103,24)+' 07:00:00') and k3106<=convert(datetime,convert(varchar(100),k3103,24)+' 15:00:00')
then DATEDIFF(MINUTE,convert(datetime,convert(varchar(100),k3103,24)+' 07:00:00'),k3106)/60.0
when k3106>convert(datetime,convert(varchar(100),k3103,24)+' 15:00:00') then 8.0
end
when k3104>convert(datetime,convert(varchar(100),k3103,24)+' 07:00:00') and k3104<=convert(datetime,convert(varchar(100),k3103,24)+' 15:00:00') then
case
when k3106<=convert(datetime,convert(varchar(100),k3103,24)+' 15:00:00') then DATEDIFF(MINUTE,k3104,k3106)/60.0
when k3106>convert(datetime,convert(varchar(100),k3103,24)+' 15:00:00') then DATEDIFF(MINUTE,k3104,convert(datetime,convert(varchar(100),k3103,24)+' 15:00:00'))/60.0
end
when k3104>convert(datetime,convert(varchar(100),k3103,24)+' 15:00:00') then 0
end
------解决方案--------------------
convert(varchar(100),k3103,24)
=>
convert(varchar(10),k3103,120)