Subject Re: [firebird-support] using case in order by statement in sp
Author Tetram Corp
hi,

try this:

order by S.Supp_Code,
case when (:indexby)=0 then
begin
F.Farm_Name /* name index
end
else begin
F.Farm_Code /* code index
end
end

or
order by
case :indexby
when 0 then Field1_0
when 1 then Field1_1
end,
case :indexby
when 0 then Field2_0
when 1 then Field2_1
end,
case :indexby
when 0 then Field3_0
end


Alan.Davies@... a écrit :
> Hi - I'm in the process of converting a number of SPs from an
> If..Then..Else construct to a Case... construct because in a number of
> them the only part which changes is the index.
> Using FB 1.5.3 Windows 2003 server and IB Expert. Lots of ram and disk.
>
> This works (and has already been applied to a number of SPs)
>
> order by case when (:indexby)=0 then Supp_Name /* name index
> else Supp_Code end /* code index
>
> But if I need more than one column as an index I get parsing errors
> and cannot compile. I guess its an issue with the case.. begin.. end
> This does not work
>
> order by case when (:indexby)=0 then
> begin
> S.Supp_Code,F.Farm_Name /* name index
> end
> else begin
> S.Supp_Code,F.Farm_Code /* code index
> end
> end
> Any suggestions please?
> Regards
> Alan
>
>
>