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 2000 Forums
 Transact-SQL (2000)
 Silly CASE DATEDIFF question

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_id

Thanks,
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' END

or

CASE WHEN MyColumnA=1 THEN 'One' WHEN MyColumnB=2 THEN 'Two' END

You are using a hybrid of the two, and need to use the second for this job

Kristen
Go to Top of Page

mlr
Starting Member

2 Posts

Posted - 2004-06-05 : 20:00:35
Thanks! It was late, couldn't think clearly
Go to Top of Page
   

- Advertisement -