Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Update statement with an If?

Author  Topic 

TJ
Posting Yak Master

201 Posts

Posted - 2002-09-11 : 11:21:48
I need to include an if statement in this piece of code but am not sure how? Is it possible?

UPDATE TAXPAYER 
SET TAXPAYER.CLIENTTYPE = CLIENTS.CLIENTTYPE, TAXPAYER.NTSDENIAL = CLIENTS.DENIALCODE,
TAXPAYER.BADBNKCODE = CLIENTS.ORGBANK, TAXPAYER.PROCSTAT = '38', TAXPAYER.PROCDTE = CURRENT_TIMESTAMP
FROM TAXPAYER
INNER JOIN CLIENTS ON TAXPAYER.PRIMSSN = CLIENTS.SECSSN
WHERE TAXPAYER.PROCSTAT = '##' AND CLIENTS.CLIENTTYPE = 'B'


I need to include:

IF LEFT(TAXPAYER.DAN, 1) = 'Q' AND CLIENTS.CLIENTTYPE = 'F'
SET TAXPAYER.NTSDENIAL = '', TAXPAYER.PROCSTAT = '38'

Any guidance would be appreciated!

Thanks!
Teresa

mr_mist
Grunnio

1870 Posts

Posted - 2002-09-11 : 11:25:23
Isn't it easier just to do a separate update for that bit?

Otherwise I imagine you could probably do it with a convoluted CASE statement.

Go to Top of Page

TJ
Posting Yak Master

201 Posts

Posted - 2002-09-11 : 11:29:06
quote:

Isn't it easier just to do a separate update for that bit?
Otherwise I imagine you could probably do it with a convoluted CASE statement.



That would have been my first choice as well. However, I've been asked to include it in this piece of code so I do not continually search through the clients table that contains 1,000,000,000 + records in it.

Thanks for responding!
Teresa
Go to Top of Page

Sitka
Aged Yak Warrior

571 Posts

Posted - 2002-09-11 : 11:47:52
Man that is one big clients table.
~1/7 of the world.
Or is it really a distribution?


Voted best SQL forum nickname...."Tutorial-D"
Go to Top of Page

TJ
Posting Yak Master

201 Posts

Posted - 2002-09-11 : 11:52:35
quote:

Man that is one big clients table.
~1/7 of the world.
Or is it really a distribution?

Voted best SQL forum nickname...."Tutorial-D"




It's really a clients table.

"Someday I'll know enough to help someone else!"
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-09-11 : 11:58:38

....
set
taxpayer.ntsdenial = case when LEFT(TAXPAYER.DAN, 1) = 'Q' AND CLIENTS.CLIENTTYPE = 'F' then '' else taxpayer.ntsdenial end, ....
....


Jay White
{0}
Go to Top of Page
   

- Advertisement -