Union e Order By - Erro

Firebird

30/01/2004

Bem eu preciso ordenar ambos selects pela data_pag.

Eu já tentei de com parenteses em em cada select e depois um order by fora, já tentei também colocar parenteses em cada select e um order by tb em cada select e eum fora ... mas não funciona ...

O código abaixo funciona certinho apenas não orderna ... gostaria de ordenar por data_pag.

[i:2aefd73df3]Select Matr, Nome, N_Cota, Valor, Data_Pag, Valor_Pag, Valor_Pag - Valor As Diferenca From Cotas, Alunos
Where Cotas.Matr = Alunos.Matr
Union
Select Matr, Nome, N_Cota, Valor, Data_Pag, Valor_Pag, Valor_Pag - Valor As Diferenca From Receitas
Where Data_Pag BetWeen :PDataI and :PDataF[/i:2aefd73df3]

Desde já agradeço.

Sds,
Fabíola


Fea

Fea

Curtidas 0

Respostas

Maicongabriel

Maicongabriel

30/01/2004

Quando você usa Union o ´Order By´ só pode ser utilizado no final ::

Select Matr, Nome, N_Cota, Valor, Data_Pag, Valor_Pag,
       Valor_Pag - Valor As Diferenca
       From Cotas, Alunos
         Where Cotas.Matr = Alunos.Matr
           Union
             Select Matr, Nome, N_Cota, Valor, Data_Pag, Valor_Pag,
                    Valor_Pag - Valor As Diferenca
                    From Receitas
                      Where Data_Pag BetWeen :PDataI and :PDataF
                        Order by Data_Pag

Este Order By não funcionando tente troca-lo por :: ´Order by 5´ que é a posição do campo ´Data_Pag´ na Select...


GOSTEI 0
POSTAR