I'm using coldfusion to retrieve some values from a database using a COUNT CASE statement.
The SQL below works perfectly well against a SQL server datasource:
<cfquery name="getData" datasource="cfTSP1_Dev">
SELECT SiteFK,
Scheme,
COUNT(case when DrawingTypeFK = 'Civil' then 1 else null end) as CCount,
COUNT(case when DrawingTypeFK = 'Mechanical' then 1 else null end) as MCount,
COUNT(case when DrawingTypeFK = 'Electrical' then 1 else null end) as ECount,
COUNT(case when DrawingTypeFK = 'P & ID' then 1 else null end) as PCount,
COUNT(case when DrawingTypeFK = 'Zoning' then 1 else null end) as ZCount
FROM Drawings.tblDrawingsData
where SiteFK = 'MYSITE'
group by SiteFK,Scheme
order by Scheme
but when I change the query to point at exactly the same table in an access database I receive an error:
<cfquery name="getData" datasource="drawingsLink">
SELECT SiteFK,
Scheme,
COUNT(case when DrawingTypeFK = 'Civil' then 1 else null end) as CCount,
COUNT(case when DrawingTypeFK = 'Mechanical' then 1 else null end) as MCount,
COUNT(case when DrawingTypeFK = 'Electrical' then 1 else null end) as ECount,
COUNT(case when DrawingTypeFK = 'P & ID' then 1 else null end) as PCount,
COUNT(case when DrawingTypeFK = 'Zoning' then 1 else null end) as ZCount
FROM tblDrawingsData
where SiteFK = 'MYSITE'
group by SiteFK,Scheme
order by Scheme
The error being this:
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'COUNT(case when DrawingTypeFK = 'Civil' then 1 else null end)'.
Any ideas why? My only theory is that its the access driver but my other queries using this datasource (without Count Case) are fine.
Cheers Neil
sum(case when .. then 1 else 0 end)
instead should not make any difference in the end result. That said, I tend to usesum
as well. – Leigh