編輯:我正確使用CASE嗎?
對不起,我沒有在開始時澄清。 CompanyType是SMALLINT,不是null,TotalLicenses爲int,空
基本上我只是想檢查TotalLicenses > 0 if C.CompanyType != 4
我看着幾個參考指南和教程,但我無法找到一個證實,我使用CASE當我打算在這個例子中。
我試圖在Expiration大於或等於Today's date時將「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
所以,如果'C.CompanyType'等於'4' ,更新應該完成? –
無論C.CompanyType是什麼,都應該進行更新,但如果公司類型不是4,則只應在TotalLicenses大於0時執行更新。 – Adam