日期:2014-05-19  浏览次数:20649 次

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 & " '
------解决方案--------------------
多条件并列?
只是重复更新而已,不影响结果