February 27, 2009 at 12:51 pm
Hi there,
I'm trying to see if there is a 'shorter' way to do a SQL statement...
UPDATE dbo.SomeTableName
SET COL1 = M.COL1,
COL2 = M.COL2,
COL3 = M.COL3,
...
...
...
COL40 = M.COL40,
COL41 = M.COL41
FROM @TBLMASTERS M
INNER JOIN dbo.SomeTableName T
ON M.ID = T.ID
WHERE
COL1 <> M.COL1 OR
COL2 <> M.COL2 OR
COL3 <> M.COL3 OR
...
...
...
COL40 <> M.COL40 OR
COL41 <> M.COL41
Is there any way to do the comparison without all of that?
thanks,
Chris
February 27, 2009 at 1:54 pm
Your query does not look like T-SQL, so I don't know if this will work in your product. In T-SQL we could use the EXCEPT operator, as in:
SELECT {column list} FROM tablea
EXCEPT SELECT {column list} FROM tableb;
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
February 27, 2009 at 3:06 pm
sorry, I thought it was pretty universal that ... means too much stuff to bother typing out
plus I fixed a typo so it reads UPDATE instead of PDATE. It is very much T-SQL though.
February 27, 2009 at 3:19 pm
Okay - wasn't sure, but since your are on SQL Server the EXCEPT operator is available and can be used.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
February 27, 2009 at 8:36 pm
Christopher...
Let's think about this... what harm would it cause if all the items were equal and we still did the update anyway? Unless you have triggers or a TIMESTAMP datatype column on the table, there is no harm. If you have neither of those items, just let the update rip.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 3, 2009 at 9:51 am
Thanks for the replies. I'll see if we can just get rid of it all.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply