读书人

sql语句的case语句解决方案

发布时间: 2012-01-30 21:15:58 作者: rapoo

sql语句的case语句
case能不能多条件并列,如题


update
TCheckDetails
set
SysQty=case when b.ProductID is null then '0 ' else '1 ' end,
SysLocationID=b.LocationID,Result=when b.ProductID is null then '4 ' when b.ProductID is not null and a.ScanLocaionID <> b.LocaionID then '2 ' else '1 ' end
From
TCheckDetails as a
left join
TStore as b
on a.ProductID=b.ProductID
and a.CheckID= ' " & strcheckid & " '


[解决办法]
写法错误,楼主说一下逻辑.
第5行加case

update
TCheckDetails
set
SysQty=case when b.ProductID is null then '0 ' else '1 ' end,
SysLocationID=b.LocationID,Result=case when b.ProductID is null then '4 ' when b.ProductID is not null and a.ScanLocaionID <> b.LocaionID then '2 ' else '1 ' end
From
TCheckDetails as a
left join
TStore as b
on a.ProductID=b.ProductID
and a.CheckID= ' " & strcheckid & " '
[解决办法]
多条件并列?
只是重复更新而已,不影响结果

读书人网 >SQL Server

热点推荐