Subject | RE: [firebird-support] What's wrong with this SQL? |
---|---|
Author | Svein Erling Tysvær |
Post date | 2011-09-20T08:48:55Z |
> I was under the impression that the query parser would recognize thatHi Kjell,
> the two expressions are identical. That's actually how it works in SQL
> Server 2008. In fact, there you HAVE to use that syntax; you CANNOT
> refer to the select list's column alias in the group by clause. I wasn't
> aware that SQL Server and Firebird are different in this respect.
>> Just change it to
>> group by 1
>> order by 1
> It's new to me that you can use the column index syntax for group by.
> Interesting. It does NOT work in SQL Server 2008...
I assume from your answer to Helen that what you really want is SQL that works with both Firebird and SQL Server 2008. So, does SQL Server 2008 support CTEs? I.e. could something like:
with TMP ("Category") as
(select case when "RemovedAt" is null then 'Cur' else 'Hist' end
from "Objects"
where "ObjectKind" = 92)
select "Category", count(*) "Count"
from TMP
group by "Category"
order by "Category"
work in both engines?
HTH,
Set