If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2 SQL Error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-23-10, 15:28
mjstamper mjstamper is offline
Registered User
 
Join Date: Aug 2010
Posts: 5
Exclamation DB2 SQL Error

Hi Everyone,

I have tried multiple solutions but to no avail. I am trying to update someones code to start working again but I am getting a select/group by error.

<code>
select pftctr.PROFIT_CENTER_CD,
terr.TERR_LVL4_CD, terr.TERR_LVL4_DE, terr.TERR_LVL5_CD, terr.TERR_LVL5_DE,
acct.ACCOUNT_LVL1_CD, acct.ACCOUNT_LVL1_DE,
acct.ACCOUNT_LVL2_CD, acct.ACCOUNT_LVL2_DE, acct.ACCOUNT_LVL3_CD, acct.ACCOUNT_LVL3_DE, acct.ACCOUNT_LVL4_CD, acct.ACCOUNT_LVL4_DE,
acct.ACCOUNT_LVL5_CD, acct.ACCOUNT_LVL5_DE, acct.ACCOUNT_LVL6_CD, acct.ACCOUNT_LVL6_DE, acct.ACCOUNT_LVL7_CD, acct.ACCOUNT_LVL7_DE,
fiscal.YEAR, fiscal.QUARTER, burden.BURDEN_DE,
SUM(vcf.UNITS) AS QUANTITY, SUM(vcf.USD_AMOUNT) AS AMOUNT_GROUP, SUM(vcf.LOCAL_AMOUNT) AS AMOUNT_LOCAL, SUM(vcf.TRANS_AMOUNT) AS TRANS_AMOUNT
from FP_WDSHE3.SHE_F_PL vcf,
FP_WDSHE3.SHE_D_TERRITORY terr,
FP_WDSHE3.SHE_D_ACCOUNT acct,
FP_WDSHE3.SHE_D_FISCAL_CALENDAR fiscal,
FP_WDSHE3.SHE_D_SCENARIO scenario,
FP_WDSHE3.SHE_D_PROFIT_CENTER pftctr,
FP_WDSHE3.SHE_D_BURDEN burden
WHERE vcf.ACCOUNT_KEY = acct.ACCOUNT_KEY
AND vcf.TERRITORY_KEY = terr.TERRITORY_KEY
AND vcf.FISCAL_CAL_KEY = fiscal.FISCAL_CAL_KEY
AND vcf.plan_YEAR = 2010
AND fiscal.QUARTER in (1,2,3)
AND vcf.SCENARIO_KEY = scenario.SCENARIO_KEY
AND scenario.SCENARIO_CD = 'ACT'
--AND scenario.VERSION_CD = 'SM1'
AND vcf.PROFIT_CTR_KEY = pftctr.PROFIT_CTR_KEY
AND vcf.BURDEN_KEY = burden.BURDEN_KEY
AND burden.BURDEN_cd in ('UBD','BGE')
GROUP BY pftctr.PROFIT_CENTER_CD,
terr.TERR_LVL4_CD, terr.TERR_LVL4_DE, terr.TERR_LVL5_CD, terr.TERR_LVL5_DE,
acct.ACCOUNT_LVL1_CD, acct.ACCOUNT_LVL1_DE,
acct.ACCOUNT_LVL2_CD, acct.ACCOUNT_LVL2_DE, acct.ACCOUNT_LVL3_CD, acct.ACCOUNT_LVL3_DE, acct.ACCOUNT_LVL4_CD, acct.ACCOUNT_LVL4_DE,
acct.ACCOUNT_LVL5_CD, acct.ACCOUNT_LVL5_DE, acct.ACCOUNT_LVL6_CD, acct.ACCOUNT_LVL6_DE, acct.ACCOUNT_LVL7_CD, acct.ACCOUNT_LVL7_DE,
fiscal.YEAR, fiscal.QUARTER, burden.BURDEN_DE
</code>

The error says it is the BURDEN_DE, so I tried removing the BURDEN_DE field but then it says it has an issue with the QUARTER field.

Any ideas on what I am missing here? Any advice is welcomed.

Thanks in advance.
mjstamper
Reply With Quote
  #2 (permalink)  
Old 08-23-10, 15:55
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by mjstamper View Post
Any advice is welcomed.
Post the error message.
Reply With Quote
  #3 (permalink)  
Old 08-23-10, 15:56
mjstamper mjstamper is offline
Registered User
 
Join Date: Aug 2010
Posts: 5
Sorry,

SQL0119N
SQLSTATE = 42803
Reply With Quote
  #4 (permalink)  
Old 08-23-10, 16:08
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
That's not a message; this looks like an error code.
Reply With Quote
  #5 (permalink)  
Old 08-23-10, 16:13
mjstamper mjstamper is offline
Registered User
 
Join Date: Aug 2010
Posts: 5
"An expression starting with "BURDEN_DE" 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."
Reply With Quote
  #6 (permalink)  
Old 08-23-10, 16:17
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
You may want to try quoting the name of the year column in FP_WDSHE3.SHE_D_FISCAL_CALENDAR. YEAR is a reserved word in DB2 and the compiler may have trouble with that.
Reply With Quote
  #7 (permalink)  
Old 08-23-10, 16:21
mjstamper mjstamper is offline
Registered User
 
Join Date: Aug 2010
Posts: 5
Hi n_i,

I tried that and I am still getting the same error.
Reply With Quote
  #8 (permalink)  
Old 08-23-10, 16:52
mjstamper mjstamper is offline
Registered User
 
Join Date: Aug 2010
Posts: 5
Figured it out.

<code>
select pftctr.PROFIT_CENTER_CD,
terr.TERR_LVL4_CD, terr.TERR_LVL4_DE, terr.TERR_LVL5_CD, terr.TERR_LVL5_DE,
acct.ACCOUNT_LVL1_CD, acct.ACCOUNT_LVL1_DE,
acct.ACCOUNT_LVL2_CD, acct.ACCOUNT_LVL2_DE, acct.ACCOUNT_LVL3_CD, acct.ACCOUNT_LVL3_DE, acct.ACCOUNT_LVL4_CD, acct.ACCOUNT_LVL4_DE,
acct.ACCOUNT_LVL5_CD, acct.ACCOUNT_LVL5_DE, acct.ACCOUNT_LVL6_CD, acct.ACCOUNT_LVL6_DE, acct.ACCOUNT_LVL7_CD, acct.ACCOUNT_LVL7_DE,
fiscal.YEAR, fiscal.QUARTER, brdn.BURDEN_DE,
SUM(vcf.UNITS), SUM(vcf.USD_AMOUNT), SUM(vcf.LOCAL_AMOUNT), SUM(vcf.TRANS_AMOUNT)

from FP_WDSHE3.SHE_F_PL vcf,
FP_WDSHE3.SHE_D_TERRITORY terr,
FP_WDSHE3.SHE_D_ACCOUNT acct,
FP_WDSHE3.SHE_D_FISCAL_CALENDAR fiscal,
FP_WDSHE3.SHE_D_SCENARIO scenario,
FP_WDSHE3.SHE_D_PROFIT_CENTER pftctr,
FP_WDSHE3.SHE_D_BURDEN brdn
WHERE vcf.ACCOUNT_KEY = acct.ACCOUNT_KEY
AND vcf.TERRITORY_KEY = terr.TERRITORY_KEY
AND vcf.FISCAL_CAL_KEY = fiscal.FISCAL_CAL_KEY
AND vcf.SCENARIO_KEY = scenario.SCENARIO_KEY
AND vcf.PROFIT_CTR_KEY = pftctr.PROFIT_CTR_KEY
AND vcf.BURDEN_KEY = brdn.BURDEN_KEY
AND vcf.PLAN_YEAR = 2010
AND fiscal.QUARTER in (1,2,3)
AND scenario.SCENARIO_CD = 'ACT'
AND brdn.BURDEN_CD in ('UBD','BGE')
GROUP BY pftctr.PROFIT_CENTER_CD,
terr.TERR_LVL4_CD, terr.TERR_LVL4_DE, terr.TERR_LVL5_CD, terr.TERR_LVL5_DE,
acct.ACCOUNT_LVL1_CD, acct.ACCOUNT_LVL1_DE,
acct.ACCOUNT_LVL2_CD, acct.ACCOUNT_LVL2_DE, acct.ACCOUNT_LVL3_CD, acct.ACCOUNT_LVL3_DE, acct.ACCOUNT_LVL4_CD, acct.ACCOUNT_LVL4_DE,
acct.ACCOUNT_LVL5_CD, acct.ACCOUNT_LVL5_DE, acct.ACCOUNT_LVL6_CD, acct.ACCOUNT_LVL6_DE, acct.ACCOUNT_LVL7_CD, acct.ACCOUNT_LVL7_DE,
fiscal.YEAR, fiscal.QUARTER, brdn.BURDEN_DE
</code>

I removed the AS in the select statement and didn't receive the error.
Reply With Quote
  #9 (permalink)  
Old 08-26-10, 09:06
mandar_57 mandar_57 is offline
Registered User
 
Join Date: Aug 2010
Posts: 3
It's gr8 learning. Thanks.
Reply With Quote
Reply

Tags
sql db2

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On