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.
| Author |
Topic |
|
mlr
Starting Member
2 Posts |
Posted - 2004-06-04 : 23:40:23
|
| I am trying to perform a case statement based on the value of a datediff calculation to change a DOB from a datetime to a range, like < 20, 21>30,etc.What am I doing wrong here?SELECT c.client_id , 'Type' = 'Loan' , d.type AS 'Disposition Type' , sex AS 'Gender' , region AS 'Region' , 'Type' = 'Loan' , avg_salary AS 'Salary' , DATEDIFF(yy, birthdate, GETDATE()) AS 'Age' /* = CASE(DATEDIFF(yy, birthdate, GETDATE())) WHEN <= 20 THEN '<=20' WHEN BETWEEN 20 AND 30 THEN '21 - 30' WHEN <= 40 THEN '31 - 40' WHEN <= 50 THEN '41 - 50' WHEN <= 60 THEN '51 - 60' WHEN <= 70 THEN '61 - 70' WHEN <= 80 THEN '71 - 80' WHEN <= 90 THEN '81 - 90' WHEN <= 100 THEN '91 - 100' END*/FROM Client c JOIN Disposition d ON c.client_id = d.client_id JOIN Loan l ON l.account_id = d.account_id JOIN Demographic dem ON c.district_id = dem.district_idThanks,Melissa |
|
|
Kristen
Test
22859 Posts |
Posted - 2004-06-05 : 03:14:36
|
| There's two sorts of WHEN in a CASE statement.CASE MyColumn WHEN 1 THEN 'One' WHEN 2 THEN 'Two' ENDorCASE WHEN MyColumnA=1 THEN 'One' WHEN MyColumnB=2 THEN 'Two' ENDYou are using a hybrid of the two, and need to use the second for this jobKristen |
 |
|
|
mlr
Starting Member
2 Posts |
Posted - 2004-06-05 : 20:00:35
|
Thanks! It was late, couldn't think clearly |
 |
|
|
|
|
|
|
|