Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Case statement in Group by clause doesn't work in DB2 10.1 but works in 9.7

$
0
0
Hi,

I have below scenario. I am just trying to avoid multiple queries by using case statement in group by clause in a Stored Procedure. I am using host variables in the case statement to decide what field to group by on. This code works fine in DB2 9.7 LUW free version. As soon as I run it on DB2 10.1 enterprise version. It gives SQL code -119. When we checked further , it says it's a problem with the host variables we are using in Group by call.
Any help would be appreciated a lot.

Error is

“DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0119N An expression starting with "REGION" specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specified. LINE NUMBER=47.
SQLSTATE=42803”

SELECT (CASE PARM_REGION_NAME WHEN 'Z1' THEN ' ' WHEN 'ALL' THEN REGION ELSE REGION END) AS REGION,
(CASE PARM_DG_NAME WHEN 'Z1' THEN ' ' WHEN 'ALL' THEN DEALER_GRP ELSE DEALER_GRP END) AS DEALER_GRP,
COALESCE(SUM(DS_TOTAL_COST), 0) AS ACTUAL_EXPENSE,
FROM ASPECT.GW_DMG_SUMM
WHERE DS_COUNTRY_CD = PARM_COUNTRY_CD
AND DS_PERIOD_TYPE = PARM_PERIOD_TYPE
GROUP by (CASE PARM_DG_NAME WHEN 'Z1' THEN ' ' WHEN 'ALL' THEN DEALER_GRP ELSE DEALER_GRP END) ,
(CASE PARM_REGION_NAME WHEN 'Z1' THEN ' ' WHEN 'ALL' THEN REGION ELSE REGION END)

It works fine at below version.
"DB2" uses 32 bits
Inform "DB2 v9.7.200.358"
Product name: "DB2 Express-C"
License type: "Unwarranted"
Expiry date: "Permanent"
Product identifier: "db2expc"

It doesn't work on below version

"DB2" uses "64" bits
Informational tokens are "DB2 v10.1.0.872"
Product name: "DB2 Enterprise Server Edition"
License type: "CPU Option"
Expiry date: "Permanent"
Product identifier: "db2ese"
Version information: "10.1"

Any help is highly appreciated.

thanks
Roop

Viewing all articles
Browse latest Browse all 13329

Trending Articles