SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


IF UDPATE(columnName) NOT EQUALS


IF UDPATE(columnName) NOT EQUALS

Author
Message
snomadj
snomadj
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3504 Visits: 836
Morning all,

I have 20 + columns. I only want my trigger to fire if any of 18 are changed. I can write ..

IF (UPDATE(col1) OR UPDATE (col2) OR UPDATE ... x 18 )
BEGIN
write to my audit table
END

But, it would be more elegant to write:

IF (UPDATE <> (col19) AND UPDATE <> (col20))
BEGIN
write to my audit table
END

Is there a not equals equivalent that would work with the IF(UPDATE)?


Failing that I could go for:
IF (UPDATE (col19) OR UPDATE (col20)
BEGIN
do nothing
END
ELSE
write to my audit table
END

I know the above is a bit pants, but it seems better than a massive OR statement.

But what could my "do nothing" code be.

Hope this is clear. It's crystal in my head!
Thomas Rushton
Thomas Rushton
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: Moderators
Points: 19480 Visits: 10158
If columns 17 & 19 are changed, what do you want to do? Fire the trigger, or not fire the trigger?

Either way, rather than checking all 20 column fields, then have a look at the COLUMNS_UPDATED function.
snomadj
snomadj
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3504 Visits: 836
Blimey! That looks complicated. Thank you Thomas. I think that's exactly what I need, just need to get my head around it. Appreciate your time / response. Sometimes it's hard to know what to google for when you don't have the right words. I'd never even heard of this function before.

Smile
ScottPletcher
ScottPletcher
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85496 Visits: 9624
I think you can use NOT:

IF NOT UPDATE(col19) AND NOT UPDATE(col20)

SQL DBA,SQL Server MVP(07, 08, 09) Prosecutor James Blackburn, in closing argument in the Fatal Vision murders trial:
If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them.
Scott Coleman
Scott Coleman
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24216 Visits: 2177
Or NOT ( UPDATE(col19) OR UPDATE(col20) )



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search