| Author |
Topic |
|
PGG_CA
Starting Member
24 Posts |
Posted - 2012-01-18 : 15:43:05
|
| How do I do this?If field1 has a null valuethen do this queryIt's the if statement that I'm having trouble writing.Thanks. |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2012-01-18 : 15:47:47
|
How about something like the following structure:IF NOT EXISTS (SELECT <field1> FROM <yourTable> WHERE <criteria equates to NOT null>)BEGIN --do this queryENDELSE --do something else HTH. |
 |
|
|
PGG_CA
Starting Member
24 Posts |
Posted - 2012-01-18 : 16:01:07
|
| Thanks ehorn, but I need to explain further what I want to do.In this particular record, if field1 is nullthen I do thiselse I do thatIn the condition statement, if this "select field1 from table where PK=1)" returns null then ... |
 |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2012-01-18 : 16:04:33
|
I see. What is the 'this' or 'that' you need to do? We can perform certain things inline using a case statement. Such as :SELECT CASE WHEN field1 IS NULL THEN <some scalar value> ELSE <some other scalar value> END FROM <yourTable> If we need to perform complex operations, we likely have to us seperate queries to perform such tasks. It really depends on the 'this' and 'that' that you require. :)HTH. |
 |
|
|
PGG_CA
Starting Member
24 Posts |
Posted - 2012-01-18 : 16:09:13
|
| There's a very complicated update procedure to do when the condition statement returns a NULL. I don't want to modify the UPDATE, just want to insert this condition that if this particular field for this record is NULL then perform the update; otherwise, don't do anything. |
 |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2012-01-18 : 16:11:04
|
| Can you simply add the NULL condition to the UPDATE statement's WHERE criteria? |
 |
|
|
PGG_CA
Starting Member
24 Posts |
Posted - 2012-01-18 : 16:48:25
|
| I'd rather not. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-01-18 : 17:27:36
|
quote: Originally posted by PGG_CA There's a very complicated update procedure to do when the condition statement returns a NULL. I don't want to modify the UPDATE, just want to insert this condition that if this particular field for this record is NULL then perform the update; otherwise, don't do anything.
From what you've said, it sounds like you will hit the DB multiple times when you only need to do it once. Assuming that is true, why would you want to perform unneeded DB operations and slow things down?Perhaps, I don't understand what you are trying to achomplish. If I've not understood you correctly, please refer to these links to help clarify what you are trying to do:http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxhttp://www.sqlservercentral.com/articles/Best+Practices/61537/ |
 |
|
|
|