编辑:
对不起,我一开始没有澄清。CompanyType 是 smallint,不为 null,TotalLicenses 是 int,null
基本上我只想检查TotalLicenses > 0 if C.CompanyType != 4
我查看了一些参考指南和教程,但找不到一个可以确认我正在使用 CASE WHEN 我打算如何在此示例中使用。
当 Expiration 大于或等于今天的日期时,我尝试将“Purchased”列更新为 1,DemoLicense 等于 0,如果公司类型不是 4,TotalLicenses 大于 0。如果是 4,则可以0
update WebCatalog.Published.DemoTracking
set Purchased = 1
from WebCatalog.Published.Company C
inner join WebCatalog.Published.RCompany RC
on C.RCompany = RC.Link
inner join WebCatalog.Published.DemoTracking DT
on C.PKey = DT.CompanyPKey and DT.Purchased = 0
where RC.Expiration >= Cast(GETDATE() as Date) and RC.DemoLicense = 0
and C.TotalLicenses >
Case
when C.CompanyType != 4 THEN 0
END