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
 General SQL Server Forums
 New to SQL Server Programming
 Case statement

Author  Topic 

Chinni
Yak Posting Veteran

95 Posts

Posted - 2008-10-02 : 10:05:11
if income field is blank or null move 0
income field = value move value


@income decimal(17,0)

set @incomeid = (select income from table)

set @income
case
WHEN (@incomeid IS NULL)THEN 0
WHEN (@incomeid='') THEN 0
ELSE (here i need the query since it has value not null or space)

end

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-02 : 12:09:19
[code]@income decimal(17,0)

set @incomeid = (select income from table)

SELECT @income=
case
WHEN (@incomeid IS NULL)THEN 0
WHEN (@incomeid='') THEN 0
ELSE field
END
FROM YourTable[/code]
Go to Top of Page

Chinni
Yak Posting Veteran

95 Posts

Posted - 2008-10-02 : 12:34:26
thanks a lot
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-03 : 02:26:53
<<
set @incomeid = (select income from table)
>>

It would throw error if the query returns more than a value. Use top 1 or max/min if needed

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Chinni
Yak Posting Veteran

95 Posts

Posted - 2008-10-03 : 10:05:00
I have a condition like

set @incomeid = (select income from table where id = 1234)

SO this may be alright
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-03 : 10:08:45
quote:
Originally posted by Chinni

I have a condition like

set @incomeid = (select income from table where id = 1234)

SO this may be alright


only if single record exists for id=1234
Go to Top of Page
   

- Advertisement -