I have a query that I am writing in MS-SQL that must check to see if the information about a client is already in the table before inserting it. If one entity has changed then the row will be inserted. The questions is can I combine operators in the where clause? Right now I have a query that looks like this:
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)
Is there any advantage or disadvantage to writing the query like this:
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)))
To me both queries work but what is the best way to write this?