Jump to content
Llaverola

DUVIDA NUMA QUERY NO SQL SERVER 2005

Recommended Posts

Llaverola

ALTER PROCEDURE ClientesGetNome
AS
BEGIN

SELECT
Nome,
Nome_Fabrica,
Cod_Factura,
Descricao,
Data_lancamento

FROM
Clientes,Facturas,Fabrica,Factura_Linhas



WHERE
Facturas.ID_Cliente = Clientes.ID_Cliente
AND Facturas.ID_Fabrica = Fabrica.ID_Fabrica
AND Facturas.ID_Factura = Factura_Linhas.ID_Factura

GROUP BY Nome



RETURN (0)
END

TA A DAR ESTE ERRO:

" Msg 8120, Level 16, State 1, Procedure ClientesGetNome, Line 5

Column 'Facturas.Cod_Factura' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

"

ALGUEM ME PODE AJUDAR?

obrigado

Share this post


Link to post
Share on other sites
Soulsick

em vez de Cod_Factura não será ID_Factura?

eu não estou muito por dentro desta parte do SQL mas acho que será disso  🤔

Share this post


Link to post
Share on other sites
José Lopes

ALTER PROCEDURE ClientesGetNome
AS
BEGIN

SELECT
Nome,
Nome_Fabrica,
Cod_Factura,
Descricao,
Data_lancamento

FROM
Clientes,Facturas,Fabrica,Factura_Linhas



WHERE
Facturas.ID_Cliente = Clientes.ID_Cliente
AND Facturas.ID_Fabrica = Fabrica.ID_Fabrica
AND Facturas.ID_Factura = Factura_Linhas.ID_Factura

GROUP BY Nome, Nome_Fabrica, Cod_Factura, Descricao,Data_lancamento



RETURN (0)
END

Quando usas um group by...tens que te referir a todos os campos que estão no select.


Quando te pedirem peixe.... ensina-os a Pescar!!Hum..lálálálá!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.