December 15, 2010 at 8:39 pm
I have a table that has value1, newvalue1, value2, newvalue2, value3, newvalue3. There is an initial insert row with a status of 'C' created from an insert trigger. The update trigger does what the insert trigger does, adding a row to the audit table with a status of 'I' for every change.
I need a query to select any rows where value1 <> newvalue1 or value2 <> newvalue2, or value3 or newvalue3. So for each row that has any one of these conditions true, it needs to be selected.
I am drawing a blank.
December 15, 2010 at 9:40 pm
It's quite simple
SELECT*
FROMTableName
WHEREvalue1 <> newvalue1
ORvalue2 <> newvalue2
ORvalue3 <> newvalue3
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
December 16, 2010 at 7:08 am
Thank you. And if I have multiple rows, how do I only test those conditions on the very last row for each order ? If I have rows of 4 lines of order 1, line 1, how can I extract only the last changed line ?
December 16, 2010 at 8:11 am
Does the table have some sort of "this rows was inserted at this time on this day" kind of column? Or at least an ID column for sequence?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
December 16, 2010 at 2:18 pm
I got it. I was just being daft. Thx!!!!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply