Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Compare values before updating

Author  Topic 

byomjan
Starting Member

34 Posts

Posted - 2009-12-22 : 12:48:34
I have a large query which updates .We dont want to update unless untill the underlying value has really changed.

update ECUSTOMER
SET CUSTOMER_POINTS = POINTS
FROM
POINTS_LOOKUP
WHERE CUSTOMER_POINTS<>POINTS

This is a simple update.requirement is to "Do not update" if there is no change in the values.


Byomjan....

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-12-22 : 14:13:14
Yes - and what is your problem?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

byomjan
Starting Member

34 Posts

Posted - 2009-12-22 : 14:29:10
i would to know if there is any other method..Its a huge sql and the "POINTS" is the result of an aggregation . ( not shown in the example though).
In short , would like to know ,if there is any other methods. to compare the updating column before UPDATE. if its not changed, then do not update.

Byomjan....
Go to Top of Page

tosscrosby
Aged Yak Warrior

676 Posts

Posted - 2009-12-22 : 15:54:33
I'm on the train and don't have access to SQL to confirm this at the moment but I would think the where clause would actually slow the update process. If the value is the same, so what? You're really not changing anything on that record. If auditing changed records is involved I can anderstand not updating it but if not, again, I think the presence of the where clause may slow performance.

Terry

-- Procrastinate now!
Go to Top of Page

byomjan
Starting Member

34 Posts

Posted - 2009-12-22 : 17:04:03
yes exactly . this is for auditing purpose. If there is no change in the values that are being updated, then no need to update that. I have used "WHERE CUSTOMER_POINTS<>POINTS" . But its slow for huge data.


Byomjan....
Go to Top of Page
   

- Advertisement -