Unix Technical Forum

sqlerr -119 when trying to produce following report

This is a discussion on sqlerr -119 when trying to produce following report within the DB2 forums, part of the Database Server Software category; --> Hi everybody! I am trying to produce following report: sum of sales value for two years group by months: ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-29-2008, 10:39 AM
lenygold via DBMonster.com
 
Posts: n/a
Default sqlerr -119 when trying to produce following report

Hi everybody!

I am trying to produce following report: sum of sales value for two years
group by months:

month 2006 2007
------- ------ --------
Jan 111.0 332.00
Feb 222.0 225.00
March 232.0 234.00
.................................
Dec 322.00 344.00

Here is my query for this report:

WITH T1(SALESDATE,SALESAMOUNT,YEAR,MONTH,MONTHNAME)
AS (SELECT MONTHEND,SALEVOL,YEAR(MONTHEND),MONTH(MONTHEND),MO NTHNAME
(MONTHEND) FROM MYSALES
ORDER BY 3,4)
Select coalesce(y1.mm,y2.mm) AS MM,coalesce(y1.mth,y2.mth) AS MONTH_NAME,
sum(y1.amt) as
YEAR_2001,sum(y2.amt) as YEAR_2002
from (select month as mm, monthname as mth, sum(SalesAmount) as amt
from T1
WHERE year = 2006
group by month, monthname) as y1
full outer join
(select month as mm, monthname as mth,sum(SalesAmount) as amt
from T1
WHERE year = 2007
group by month, monthname) as y2
on y2.mth = y1.mth
order by coalesce(y1.mm,y2.mm);

But i got the following error:
sqlcode: -119
An expression starting with "MONTH_NAME 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. SQLSTATE=4280

Any idea what is wrong with this query?
Thank's in advance. Leny G.

--
Message posted via http://www.dbmonster.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-29-2008, 10:39 AM
Tonkuma
 
Posts: n/a
Default Re: sqlerr -119 when trying to produce following report

The error -119 may be solved by adding "GROUP BY
coalesce(y1.mm,y2.mm),coalesce(y1.mth,y2.mth)".
But, looking into your required output, it must be not neccesary to
include "coalesce(y1.mm,y2.mm) AS MM "in SELECT list.

Here is an example:
WITH T1(SALESAMOUNT,YEAR,MONTH,MONTHNAME)
AS (SELECT SALEVOL,YEAR(MONTHEND),
MONTH(MONTHEND),SUBSTR(MONTHNAME (MONTHEND),1,12)
FROM MYSALES
)
Select coalesce(y1.mth,y2.mth) AS "month",
sum(y1.amt) as "2006", sum(y2.amt) as "2007"
from (select month as mm, monthname as mth, sum(SalesAmount) as amt
from T1
WHERE year = 2006
group by month, monthname) as y1
full outer join
(select month as mm, monthname as mth,sum(SalesAmount) as amt
from T1
WHERE year = 2007
group by month, monthname) as y2
on y2.mth = y1.mth
GROUP BY coalesce(y1.mm,y2.mm),coalesce(y1.mth,y2.mth)
order by coalesce(y1.mm,y2.mm)
;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-29-2008, 10:39 AM
lenygold via DBMonster.com
 
Posts: n/a
Default Re: sqlerr -119 when trying to produce following report

Thank You very much Tonkuma for your help it is working perfect:
Here is the output after your fix:

month 2006($mln) 2007($mln)
------------ ------------------- ------------------
January 337 354
February 366 409
March 431 437
April 379 412
May 419 481
June 425 403
July 397 462
August 421 465
September 434 417
October 441 405
November 455 407
December 406 380

12 record(s) selected.

One more question: T1 table data for 10 years from 1998 thru 2007.
Is there a generic way to build such report without adding 8 more outer joins
to existing query?
Thank's in advance Leny G.


Tonkuma wrote:
>The error -119 may be solved by adding "GROUP BY
>coalesce(y1.mm,y2.mm),coalesce(y1.mth,y2.mth)".
>But, looking into your required output, it must be not neccesary to
>include "coalesce(y1.mm,y2.mm) AS MM "in SELECT list.
>
>Here is an example:
>WITH T1(SALESAMOUNT,YEAR,MONTH,MONTHNAME)
> AS (SELECT SALEVOL,YEAR(MONTHEND),
> MONTH(MONTHEND),SUBSTR(MONTHNAME (MONTHEND),1,12)
> FROM MYSALES
> )
>Select coalesce(y1.mth,y2.mth) AS "month",
> sum(y1.amt) as "2006", sum(y2.amt) as "2007"
> from (select month as mm, monthname as mth, sum(SalesAmount) as amt
> from T1
> WHERE year = 2006
> group by month, monthname) as y1
> full outer join
> (select month as mm, monthname as mth,sum(SalesAmount) as amt
> from T1
> WHERE year = 2007
> group by month, monthname) as y2
> on y2.mth = y1.mth
> GROUP BY coalesce(y1.mm,y2.mm),coalesce(y1.mth,y2.mth)
> order by coalesce(y1.mm,y2.mm)
>;


--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums....m-db2/200805/1

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-29-2008, 10:39 AM
Lennart
 
Posts: n/a
Default Re: sqlerr -119 when trying to produce following report

On May 27, 9:48 pm, "lenygold via DBMonster.com" <u41482@uwe> wrote:
> Thank You very much Tonkuma for your help it is working perfect:
> Here is the output after your fix:
>
> month 2006($mln) 2007($mln)
> ------------ ------------------- ------------------
> January 337 354
> February 366 409
> March 431 437
> April 379 412
> May 419 481
> June 425 403
> July 397 462
> August 421 465
> September 434 417
> October 441 405
> November 455 407
> December 406 380
>
> 12 record(s) selected.
>
> One more question: T1 table data for 10 years from 1998 thru 2007.
> Is there a generic way to build such report without adding 8 more outer joins
> to existing query?
> Thank's in advance Leny G.
>
>
>
> Tonkuma wrote:
> >The error -119 may be solved by adding "GROUP BY
> >coalesce(y1.mm,y2.mm),coalesce(y1.mth,y2.mth)".
> >But, looking into your required output, it must be not neccesary to
> >include "coalesce(y1.mm,y2.mm) AS MM "in SELECT list.

>
> >Here is an example:
> >WITH T1(SALESAMOUNT,YEAR,MONTH,MONTHNAME)
> > AS (SELECT SALEVOL,YEAR(MONTHEND),
> > MONTH(MONTHEND),SUBSTR(MONTHNAME (MONTHEND),1,12)
> > FROM MYSALES
> > )
> >Select coalesce(y1.mth,y2.mth) AS "month",
> > sum(y1.amt) as "2006", sum(y2.amt) as "2007"
> > from (select month as mm, monthname as mth, sum(SalesAmount) as amt
> > from T1
> > WHERE year = 2006
> > group by month, monthname) as y1
> > full outer join
> > (select month as mm, monthname as mth,sum(SalesAmount) as amt
> > from T1
> > WHERE year = 2007
> > group by month, monthname) as y2
> > on y2.mth = y1.mth
> > GROUP BY coalesce(y1.mm,y2.mm),coalesce(y1.mth,y2.mth)
> > order by coalesce(y1.mm,y2.mm)
> >;

>


IMO sql is not the right tool to do presentation, but perhaps you can
use something like:

SELECT MONTH(MONTHEND),
sum(case when YEAR(MONTHEND) = 1997 then SALEVOL else 0
end) as Sum1997,
sum(case when YEAR(MONTHEND) = 1998 then SALEVOL else 0
end) as Sum1998,
[...]
FROM MYSALES

/Lennart

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:22 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com