我有一個查詢,我在MS-SQL中編寫,必須檢查,以查看有關客戶端的信息是否已經在表中插入之前。如果一個實體已經改變,那麼該行將被插入。問題是我可以在where子句中結合運算符嗎?現在我有一個查詢,看起來像這樣:sql組合多個運營商
select * from @Temp c
where exists (select * from Clients c2
where (c.ClientId = c2.ClientId and c.ClientFName <> c2.FirstName)
or (c.ClientId = c2.ClientId and c.ClientLName <> c2.LastName)
or (c.ClientId = c2.ClientId and c.ClientAddress <> c2.Address)
or (c.ClientId = c2.ClientId and c.ClientCity <> c2.City)
or (c.ClientId = c2.ClientId and c.ClientState <> c2.State)
or (c.ClientId = c2.ClientId and c.ClientZip <> c2.Zip)
有什麼優勢或劣勢編寫這樣的查詢:
select * from @Temp c
where exists (select * from Clients c2
where (c.ClientId = c2.ClientId
and (c.ClientFName <> c2.FirstName
or c.ClientLName <> c2.LastName
or c.ClientAddress <> c2.Address
or c.ClientCity <> c2.City
or c.ClientState <> c2.State
or c.ClientZip <> c2.Zip)))
對我來說,這兩個查詢工作,但什麼是最好的方式寫這個?