Subject Re: Nasty query construct problem
Author johanfredse
--- In firebird-support@yahoogroups.com, Lucas Franzen <luc@r...>
wrote:
>
> Johan,
>
> > The "artno" is used to select xxxx or yyyy for making it to two
> > columns in the result.
> >
> > Any ideas on how to make that kind of SP? Thats new for me!
> >
> > Thanks for helping.
> > /Johan
>
> The problem is that you have to take care for EVERY KIND of artno
you've
> got since you want convert a "vertical" information (the value of
artno
> in your records) in a horizontal one (a column for each).
>
> So for every distinct artno you've got, you want to have two
columns
> back (in your example you've got artno xxxx and yyyy and you want
> columns for: xxxx nett, xxxx gross, yyyy nett, yyyy gross)
>
> This is just impossible, columns that should be returned have to be
> defined in advance.
>
> If you really got just two artno values you can do it with a stored
proc.
> But before I'll write you an example it's better to ask if that's
what
> you want! ;-)
>
>
> Regards
> Luc.

Hmm...it's even worse I think! In my example I used xxxx and yyyy but
in real life it's xxxx i want in the first column and whatever else
in the second column. The yyyy can be infinit number of variants!

I'm thinking of doing a datamoving routine before my actual sql that
moves each row into a new table and in that move put it in column one
or two and do a per row sum also.

After that it should be straigh forward for a sql query and grouping.

Cheers
/Johan