where 1 or more is true

  • 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.

  • It's quite simple

    SELECT*

    FROMTableName

    WHEREvalue1 <> newvalue1

    ORvalue2 <> newvalue2

    ORvalue3 <> newvalue3


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • 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 ?

  • 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

  • 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