2013-10-22 169 views
0

我想說的是: 「如果RC.Expiration大於或等於今天的日期,並且RC.DemoLicense等於0,那麼設置DemoTracking.Purchased爲1」我只需要查看DT所在的條目。購買0我是否正確地使用更新?

update WebCatalog.Published.DemoTracking 
set Purchased = 1 
from WebCatalog.Published.RCompany RC 
inner join WebCatalog.Published.DemoTracking DT 
    on RC.Link = DT.RCompanyLink and DT.Purchased = 0 
where RC.Expiration >= GETDATE() and RC.DemoLicense = 0 
+3

我希望移居'DT.Purchased = 0'到WHERE子句,但它是主觀的,它會工作相同的反正。乍一看看你的查詢應該正常工作。 –

+2

GetDate()返回一個日期時間,這會導致您錯過當天早些時候的記錄。要解決此問題,請將getdate()作爲日期。 –

回答

0

試試這個

update WebCatalog.Published.DemoTracking 
set Purchased = 1 
where Purchased = 0 and RCompanyLink in (select Link as RCompanyLink from WebCatalog.Published.RCompany where RC.Expiration >= GETDATE() and RC.DemoLicense = 0)