Fórum Union e Order By - Erro #41909
30/01/2004
0
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
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
Curtir tópico
+ 0
Responder
Posts
30/01/2004
Maicongabriel
Quando você usa Union o ´Order By´ só pode ser utilizado no final ::
Este Order By não funcionando tente troca-lo por :: ´Order by 5´ que é a posição do campo ´Data_Pag´ na Select...
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...
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)