Subject | Re: [firebird-support] records to columns |
---|---|
Author | Alan.Davies@aldis-systems.co.uk |
Post date | 2008-08-21T21:42:35Z |
Try this:
for SELECT
case
when col=1
then coalesce(SUM(IMPORTE),0)
else 0
end,
when col=2
then coalesce(SUM(IMPORTE),0)
else 0
end,
when col=3
then coalesce(SUM(IMPORTE),0)
else 0
end,
when col=4
then coalesce(SUM(IMPORTE),0)
else 0
end,
when col=5
then coalesce(SUM(IMPORTE),0)
else 0
end,
FROM
FAC
INTO
:OUT_COL1,:OUT_COL2,:OUT_COL3,:OUT_COL4,:OUT_COL5;
coalesce is there in case you have a null and don't want to process that.
Alan
--
Alan J Davies
Aldis
Quoting "Sergio H. Gonzalez" <shg_sistemas@...>:
for SELECT
case
when col=1
then coalesce(SUM(IMPORTE),0)
else 0
end,
when col=2
then coalesce(SUM(IMPORTE),0)
else 0
end,
when col=3
then coalesce(SUM(IMPORTE),0)
else 0
end,
when col=4
then coalesce(SUM(IMPORTE),0)
else 0
end,
when col=5
then coalesce(SUM(IMPORTE),0)
else 0
end,
FROM
FAC
INTO
:OUT_COL1,:OUT_COL2,:OUT_COL3,:OUT_COL4,:OUT_COL5;
coalesce is there in case you have a null and don't want to process that.
Alan
--
Alan J Davies
Aldis
Quoting "Sergio H. Gonzalez" <shg_sistemas@...>:
> 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
>
>