Subject RE: [firebird-support] records to columns
Author Svein Erling Tysvær
I sometimes do something like:

SELECT sum(case when col=1 then Importe else 0 end) as OutCol1,
sum(case when col=2 then Importe else 0 end) as OutCol2,
sum(case when col=3 then Importe else 0 end) as OutCol3,
sum(case when col=4 then Importe else 0 end) as OutCol4,
sum(case when col=5 then Importe else 0 end) as OutCol5
FROM FAC
WHERE col between 1 and 5

Although I rarely use stored procedures, so you'll have to modify things a little bit...

HTH,
Set

-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of Sergio H. Gonzalez
Sent: 21. august 2008 22:13
To: firebird-support@yahoogroups.com
Subject: [firebird-support] records to columns

Hello I have an stored procedure to make a report and I need to conver the data
of a sum of some records into a column. So far I'm doing this, and it works
without problem, but I just wander if there is other way to do it, since the
selects I'm using are equal to each other but jyst une number in a var name...

If I just could reference a var by its name (with a string) like I did some
years ago with Clipper... :)

SELECT
SUM(IMPORTE)
FROM
FAC
WHERE
(COL = 1)
INTO
:OUT_COL1;

SELECT
SUM(IMPORTE)
FROM
FAC
WHERE
(COL = 2)
INTO
:OUT_COL2;


SELECT
SUM(IMPORTE)
FROM
FAC
WHERE
(COL = 3)
INTO
:OUT_COL3;

and so on... until col5

Any other way to do the same in a FB stored procedure?

Thanks !

-sergio