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 Help?

Author  Topic 

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2007-01-23 : 14:01:19
hi,

I want to use 2 fields(result(varchar),deep(decimal)) of my table in a case statement. But it did NOT work. Would you please help me?
...
case
when s.result ='E' then 'E'
when s.result ='A' then 'GELMEYEN'
case
when s.deep < 1.0 then 'MDL-0.99'
when s.deep between 1.0 and 4.9 then '1.0-4.9'
when s.deep between 5.0 and 9.9 then '5.0-9.9'
when s.deep between 10.0 and 14.9 then '10.0-14.9'
when s.deep between 15.0 and 19.9 then '15.0-19.9'
when s.deep between 20.0 and 29.9 then '20.0-29.9'
when s.deep > 30.0 then '>30.0'
when s.deep > 0.1 then 'MDL'
END as SONUC
....

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-01-23 : 14:02:48
you'll have to "AND" the conditions together or explain in more detail what you want exactly.



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

sshelper
Posting Yak Master

216 Posts

Posted - 2007-01-23 : 14:08:41
If you are trying to concatenate the result of your 2 CASE statements into 1 column, try this:

CASE
when s.result ='E' then 'E'
when s.result ='A' then 'GELMEYEN' END +
CASE
when s.deep < 1.0 then 'MDL-0.99'
when s.deep between 1.0 and 4.9 then '1.0-4.9'
when s.deep between 5.0 and 9.9 then '5.0-9.9'
when s.deep between 10.0 and 14.9 then '10.0-14.9'
when s.deep between 15.0 and 19.9 then '15.0-19.9'
when s.deep between 20.0 and 29.9 then '20.0-29.9'
when s.deep > 30.0 then '>30.0'
when s.deep > 0.1 then 'MDL'
END as SONUC


SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2007-01-23 : 14:09:23
well,
what i wanna do is, grouping those values coming from CASE statement.
select t.SONUC,count(*) as TOPLAM FROM
(select
case
when s.sonuc ='E' then 'E'
when s.sonuc ='A' then 'GELMEYEN'
case
when s.deep < 1.0 then 'MDL-0.99'
when s.deep between 1.0 and 4.9 then '1.0-4.9'
when s.deep between 5.0 and 9.9 then '5.0-9.9'
when s.deep between 10.0 and 14.9 then '10.0-14.9'
when s.deep between 15.0 and 19.9 then '15.0-19.9'
when s.deep between 20.0 and 29.9 then '20.0-29.9'
when s.deep > 30.0 then '>30.0'
when s.deep > 0.1 then 'MDL'
END as SONUC
from
(dzmt.sonuc s
LEFT OUTER JOIN dzmt.dagitim d ON s.dagitimid = d.id),dzmt.priyotlar p
where
d.periyodid = p.id and
p.yil = 2007) as t
group by SONUC
Go to Top of Page

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2007-01-23 : 14:13:14
when i use + to concat, gives error:

The data type of an operand of an arithmetic function or operation "+ " is not numeric
Go to Top of Page
   

- Advertisement -