Subject How to change row data into columnar data
Author Alan.Davies@aldis-systems.co.uk
Using FB 2.1 - no problems with FB itself, working great.
Hi, I'm not sure if that expalins what I want to do. I have an SP
which returns all the data I require but in a record-by-record format,
as follows:

begin
for select w.date_in,
gl.gl_name,gl.gl_code,
coalesce(sum(w.tonnes),0)
from weigh w
join gl_codes gl
on gl.gl_code=w.fuel_code
where w.date_in between :fromdate and :uptodate
group by w.date_in,
gl.gl_code,gl.gl_name
into :date_in,
:gl_name,
:gl_code,
:tonnes
do suspend;
end

and this is the result (ignore any formatting that's a cut & paste matter)
Notice that daily data can be any combination of GL_NAME

DATE_IN GL_CODE GL_NAME TONNES
05/15/2009 501110 Contract Litter 1234.02
05/15/2009 501120 Contract Biomass 878.7
05/15/2009 501210 Spot Litter 48.34
05/15/2009 501220 Spot Biomass 514.69
05/16/2009 501110 Contract Litter 865
05/16/2009 501120 Contract Biomass 36.36
05/18/2009 501110 Contract Litter 391.5
05/18/2009 501120 Contract Biomass 667.64
05/18/2009 501220 Spot Biomass 505.36
05/19/2009 501110 Contract Litter 233.73
05/19/2009 501120 Contract Biomass 442.79
05/19/2009 501220 Spot Biomass 410.72

What I want is this:
DATE_IN Contract Litter Contract Biomass Spot Litter Spot Biomass
05/15/2009 1234.02 878.7 48.34 514.69
05/16/2009 865 36.36 0 0
05/18/2009 391.5 667.64 0 505.36

I thought about creating a table with this layout and populating it by
selecting from the existing SP in a second SP, such as
begin
insert into newtable
select distinct(date_in) from SP;
update newtable
set Contract Litter=(select tonnes from SP where
SP.date_in=newtable.date_in and SP.GL_NAME=newtable.GL_NAME) (you get
the idea)

But I think there is a way to do this with a procedure using while..next.
Am I right in thinking this or should I just carry on with creating
the new table?

Thanks Alan
--
Alan J Davies
Aldis