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.
| Author |
Topic |
|
riesbrink
Starting Member
1 Post |
Posted - 2012-02-08 : 09:31:09
|
| HiI am trying to compare the values in two rows, just to make clear they are the same row from the same table on is in a TempTable just before the row is updated and the other from the updated row, what I am looking to do is to compare the values of the cells in the rows to see what has been updated in the row.select * into #myTemp from tUsers where UID = @UIDselect * from tUsers where UID = @UIDCREATE TABLE dbo.tUserChanges(cID int IDENTITY (1,1),cChangeDate DateTime,cValueChanged varchar(30),cPreviousValue bit,cCurrentValue bit)So what I need to do is compare is columns cell value to the other tables values and insert in into the tUserChanges table when they are differentThanks your help will be appreciated |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-02-08 : 09:42:28
|
It would be nice to have sample tables and sample data...something like this:selectid,case when t1.col1 <> t2.col1 then 'changed' else 'equal' end as WhatHappened,t1.col1 as t1Col1,t2.col1 as t2Col1from TempTable t1join OrgTable t2 on t2.id = t1.id No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-08 : 14:13:49
|
quote: Originally posted by riesbrink HiI am trying to compare the values in two rows, just to make clear they are the same row from the same table on is in a TempTable just before the row is updated and the other from the updated row, what I am looking to do is to compare the values of the cells in the rows to see what has been updated in the row.select * into #myTemp from tUsers where UID = @UIDselect * from tUsers where UID = @UIDCREATE TABLE dbo.tUserChanges(cID int IDENTITY (1,1),cChangeDate DateTime,cValueChanged varchar(30),cPreviousValue bit,cCurrentValue bit)So what I need to do is compare is columns cell value to the other tables values and insert in into the tUserChanges table when they are differentThanks your help will be appreciated
compare based on what?you need to define for us key columns based on which we need to compare and also columns which needs to be looked for the changes.as per above selected both tables will have same data------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|