Subject CAST() in Group By clause causes no records to be returned
Author Jason Dodson
Hey all,

Making this as sinple as possible... we have a table with a bunch of simple
money transactions records. One of the fields we have in there is a called
SortedBy, which is supplied by the customer of said transactions. Because the
customer can supply literally anything for that field, it is defined as a

I needed to gather some data for one of the customers, who only uses integers
inside of the SortedBy field. Just trying to be nice and sort the data for the
customer, I wrote a query that looked like this:

Select SortedBy, sum(MyFees) as FeesTotal, sum(MyTaxes) as TaxesTotal
From MyTable
Group By SortedBy
Order By Cast(SortedBy as Integer);

Now, without the Order By clause, I get back every bit of data I would expect.
Adding the above order clause, it returns 0 records. Just to be clear, there was
no error... just no records were returned. If I change the cast() to .. say
varchar(200) or something, it runs fine. Is this a bug?

Firebird 1.5.2 on Gentoo Linux.