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
 Query Update

Author  Topic 

shajimanjeri
Posting Yak Master

179 Posts

Posted - 2010-06-16 : 07:25:30
Dear all,

I have a table with three fields Id as int, Eligible as varchar, Commission as decimal

Data stored in my table as below:
Id = 1 Eligible = Yes Commission = 1000
Id = 2 Eligible = No Commission = 0
Id = 3 Eligible = No Commission = 678
like as these.
But here my issue is that I want to make
Commission = 0 if Eligible = No.
See in the above table the third row shows Commission=678 but Eligible = 0, so I want to make Commission = 0 in my query.

select Eligible as Eligible, convert(varchar,CAST(IsNull(Commission,0) AS decimal(20,0))) as Commission from v_commission_values

Can any one Just update this query with those changes please

Thanks in advance,,
regards









jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-06-16 : 07:35:38
select Eligible as Eligible
,CASE
WHEN eligible = 'YES' THEN convert(varchar,CAST(IsNull(Commission,0) AS decimal(20,0)))
ELSE 0
END as Commission
from v_commission_values


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

shajimanjeri
Posting Yak Master

179 Posts

Posted - 2010-06-16 : 07:39:20

Perfect, many thanks mr. Jim

regards
Shaji
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-16 : 08:22:43
quote:
Originally posted by jimf

select Eligible as Eligible
,CASE
WHEN eligible = 'YES' THEN convert(varchar,CAST(IsNull(Commission,0) AS decimal(20,0)))
ELSE 0
END as Commission
from v_commission_values


Jim

Everyday I learn something that somebody else already knew


When you convert to character datatypes, make sure to specify the length
http://beyondrelational.com/blogs/madhivanan/archive/2007/12/04/column-length-and-data-length.aspx

Madhivanan

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

- Advertisement -