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 2008 Forums
 Transact-SQL (2008)
 Nested Case stuck on syntax

Author  Topic 

mole999
Starting Member

49 Posts

Posted - 2014-09-19 : 11:13:09
Hi
I have
   select 
Case WHEN RTC.liability IN ('L','EL','LVL') then '1'
Else '' End As Rep_Liable
From
accinv_rec As RTC

and
      select
case
when RTC.age >= 18 and RTC.age <20 then '<20'
when RTC.age >= 20 and RTC.age <25 then '<25'
when RTC.age >= 25 and RTC.age <30 then '<30'
when RTC.age >= 30 and RTC.age <35 then '<35'
when RTC.age >= 35 and RTC.age <40 then '<40'
when RTC.age >= 40 and RTC.age <45 then '<45'
when RTC.age >= 45 and RTC.age <50 then '<50'
when RTC.age >= 50 and RTC.age <55 then '<55'
when RTC.age >= 55 and RTC.age <60 then '<60'
when RTC.age >= 60 and RTC.age <65 then '<65'
when RTC.age >= 65 and RTC.age <70 then '<70'
when RTC.age >= 70 then '70+'
else '' end as L_Age_Group
from
accinv_rec As RTC

and I can't get a handle on embedding the latter into the former i.e. WHEN RTC.liability IN ('L','EL','LVL')is met then
when RTC.age >= 65 and RTC.age <70 then '<70'
etc I've tried what seems like dozens of variations and i get CASE warnings or WHEN . I guess i'm wrapping it wrongly but can't figure a way to build and test this taht exposes my error.

If there is a way of reducing the second down, I'd be much obliged for that also

Mole

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2014-09-19 : 11:18:05
Need more details, don't fully understand what you want, but you can easily embed on CASE within another one:


select
Case WHEN RTC.liability IN ('L','EL','LVL') then
case
when RTC.age >= 70 then '70+'
when RTC.age >= 65 then '<70'
when RTC.age >= 60 then '<65'
when RTC.age >= 55 then '<60'
when RTC.age >= 50 then '<55'
when RTC.age >= 45 then '<50'
when RTC.age >= 40 then '<45'
when RTC.age >= 35 then '<40'
when RTC.age >= 30 then '<35'
when RTC.age >= 25 then '<30'
when RTC.age >= 20 then '<25'
when RTC.age >= 18 then '<20'
else '' end
Else '' End As [...]
From
accinv_rec As RTC

Go to Top of Page

mole999
Starting Member

49 Posts

Posted - 2014-09-19 : 11:21:17
Scott thank you very much, thats what I was trying to do, and getting it wrong

I can see it now Else End Else END which threw me

obliged

Mole
Go to Top of Page
   

- Advertisement -