I created a dummy object in sql server. The select is ‘A’. It works great when I use it with a detail object. When I include a properly designed measure…one with a function such as sum() around the table.column, it won’t work. It warns me that…
GROUP BY expressions must refer to column names that appear in the select list
The ‘A’ DOES appear in the select and the GROUP BY. Shaun (my local top notch DBA :-)) tricked it into working by having me put a max() around my ‘A’ to get it OUT of the GROUP BY. It worked! Why did I get the error in the first place?
The fact that the ‘A’ appeared in the Group By should indicate that it was not recognized as an aggregate, but it was originally. But how did you create the dummy in the first place as ‘A’ as a Sum() of a field? Very strange. In any case SQL will not allow you to use an alias in the group by, you have to refer to the actual definition…
I assume it fails if it’s the ONLY other object that is being selected. HARD-CODED values should not appear in GROUP-BY clauses, as they are un-needed, but they don’t harm anything. Normally you just want the other dimensions to appear in the group-by.
With at least one valid group-by object, I think you’d be ok.
I was sure ORACLE runs fine with only one item in the group by… in fact, it won’t complain if you don’t have the hard-coded values in the group by at all.
My inexperience with SqlServer syntax shows here, since I don’t know how it will respond.
I did this sample query on sql server and it worked well.
Select ‘a’, custnumber, count(custname) test from customer
group by custnumber.
Initially, I included ‘a’ in the group by clause and reproduced the error that you indicated. I removed ‘a’ from the group by clause and it worked . did you try that?
That was my workaround. I changed ‘a’ to sum(‘a’) to get the ‘a’ out of the group by. The error complained that the ‘a’ wasn’t in the group by but it WAS . The error went away when I made sure it WASN’T in the group by. Very confusing!
SQL Server doesn’t allow use of Alias name in the group by expression and ‘A’ is being treated as alias name rather than a column name. Another SQL SERVER special…
… AND it is the same with DB2. DB2 does not allow for Group by clauses which are either constants (numbers, character strings, or expressions) so you have the problem there as well.
Even if you use ORACLE you might encounter this problem. We had a 3 machine parallel Sever Instance (really huge database on it) running at a customer site and for some bug (as I recall) in combination with the hardware product this query either crashed the server or returned random results and similar things… But this was in one of the earlier V8 versions, so don’t panic.
For the DB2, btw, there are additional parameters in the .PRM file, which control the behaviour of SQL generation:
GROUPBY_EXCLUDE_COMPLEX=Y
GROUPBY_WITHOUT_CONSTANT=Y
The manuals originally said, that these are for DB2 only, in my V5.1.5 it says you can use the latter for other DBs as well by copying it into the [RDBMS] (GENERAL) section of the .PRM file.