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 When Alternative

Author  Topic 

rc1138
Starting Member

35 Posts

Posted - 2010-05-20 : 22:50:48
Hi All,

Is there an alternative to using the Case When syntax ? There seems to be a compatibility issue with the driver that I will be using and was told that it may not be possible to use Case When.

This is the SQL query I have

"SELECT [Less Than 6 months] = COUNT(CASE WHEN DATEDIFF(Month, E.EmployDt, I.IncDate) < 6 THEN 1 END),

[6 Months - Year] = COUNT(CASE WHEN DATEDIFF(Month, E.EmployDt, I.IncDate) BETWEEN 6 AND 12 THEN 1 END),

[1 Year - 5 Years] = COUNT(CASE WHEN DATEDIFF(Month, E.EmployDt, I.IncDate) BETWEEN 13 AND 60 THEN 1 END),

[5 Years - 10 Years] = COUNT(CASE WHEN DATEDIFF(Month, E.EmployDt, I.IncDate) BETWEEN 61 AND 120 THEN 1 END),

[More than 10 Years] = COUNT(CASE WHEN DATEDIFF(Month, E.EmployDt, I.IncDate) > 120 THEN 1 END)

FROM irIncident AS I INNER JOIN pdEmployee AS E ON I.EmpKey = E.EmpKey
WHERE (E.Department = '" + StoreNum + "') AND (I.HlthCare = 'Y') AND (I.IncDate >= '" + beginDate + "')

AND (I.IncDate <= '" + endDate + "')

The table outputs as follows

Less Than 6 months||6 months - Year||1-5 Years||5 Years - 10 Years|| More than 10 years

0||0||1||2||0

Thanks again

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-05-20 : 23:48:09
What driver is this ? Whats the error message ?



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

rc1138
Starting Member

35 Posts

Posted - 2010-05-20 : 23:51:13
The driver has not been implemented yet actually its an ODBC Relativity driver
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-05-21 : 10:23:39
Are you sure its the CASE statement? What is the error?

1. You could try using ANSI style aliases using the AS clause.
2. Perhaps try aliased column names that do not require delimiting (see rules for naming identifiers in BOL).
Go to Top of Page
   

- Advertisement -