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 2005 Forums
 Transact-SQL (2005)
 Make "case" work for an "exec sp"?

Author  Topic 

Kurmanc
Yak Posting Veteran

92 Posts

Posted - 2008-01-22 : 05:58:41
Today it looks something like this:
....

SELECT
id = CASE WHEN (amount1 = 0 OR amount1 IS NULL) THEN 10 END
,total = CASE WHEN (amount1 IS NULL) THEN amount2 END
FROM Order

I want to handle amount1 = 0 for total. But I know following doesn't work:

WHEN (amount1 = 0) THEN exec sp_Test 3, 3, 0

Can I make it work with an if-statment inside the select? Note, amount1=0 exists inside "id = CASE...", so an if-statement for amount1=0 for total shouldn't affect amount1=0 for id.


Thx in advance.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-01-22 : 06:13:01
You can't do that with CASE.

Please make sure you read this: http://weblogs.sqlteam.com/jeffs/jeffs/archive/2007/05/03/60195.aspx

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Kurmanc
Yak Posting Veteran

92 Posts

Posted - 2008-01-22 : 06:27:45
harsh_athalye,

I understand. That is why I asked members if they have an idea how to solve my question with an if-statement.
Go to Top of Page

Kurmanc
Yak Posting Veteran

92 Posts

Posted - 2008-01-22 : 07:01:48
Hi,

I managed to solve it with an if/else-statement.

Regards
Go to Top of Page
   

- Advertisement -