Tuesday, March 20, 2012

Check for Null values in Transact Sql

I am using Visual Web Developer Express 2005 and SQL Server Express 2005.

I have set up a trigger that fires when an update has been performed on
a specific table. The trigger checks to see if specific columns have
been updated. If they have, then the trigger code is executed. This part
works fine.

I am now trying to find a way to check if null values exist in either
one of two field from the same table. If either field contains a null
value, then I don't want the trigger code to be executed.

How can I check for null values and skip a block of code within my
Transact Sql trigger.

Thanks....

You can use the IS NULL clause to test a column...

|||

Use something like:

if exists (select * from MyTbl where Col1 is null or Col2 is null)

//do not update

else //update

No comments:

Post a Comment