I am connecting to a MSSQL database through ODBC and I am tryint to execute the following query which I created using the query editor:
SELECT "CobroV"."NumRecibo", "CobroV"."Id_Cobro", SUM( "CobroVEstCobro"."Importe" ) "Pagat" FROM { oj "VFIN1"."dbo"."CobroVEstCobro" "CobroVEstCobro" RIGHT OUTER JOIN "VFIN1"."dbo"."CobroV" "CobroV" ON "CobroVEstCobro"."IdFinca" = "CobroV"."IdFinca" AND "CobroVEstCobro"."IdDepto" = "CobroV"."IdDepto" AND "CobroVEstCobro"."IdInquilino" = "CobroV"."IdInquilino" AND "CobroVEstCobro"."NumRecibo" = "CobroV"."NumRecibo" AND "CobroVEstCobro"."FechaExped" = "CobroV"."FechaExped" } WHERE "CobroV"."FechaExped" > {d '2022-11-01' } GROUP BY "CobroV"."Id_Cobro"
When I try executing the query I get the error:
[Microsoft][ODBC SQL Server Driver][SQL Server]Column ‘VFIN1.dbo.CobroV.NumRecibo’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
This other query on the other side works fine:
SELECT "CobroV"."Id_Cobro", SUM( "CobroVEstCobro"."Importe" ) "Pagat" FROM { oj "VFIN1"."dbo"."CobroVEstCobro" "CobroVEstCobro" RIGHT OUTER JOIN "VFIN1"."dbo"."CobroV" "CobroV" ON "CobroVEstCobro"."IdFinca" = "CobroV"."IdFinca" AND "CobroVEstCobro"."IdDepto" = "CobroV"."IdDepto" AND "CobroVEstCobro"."IdInquilino" = "CobroV"."IdInquilino" AND "CobroVEstCobro"."NumRecibo" = "CobroV"."NumRecibo" AND "CobroVEstCobro"."FechaExped" = "CobroV"."FechaExped" } WHERE "CobroV"."FechaExped" > {d '2022-11-01' } GROUP BY "CobroV"."Id_Cobro"
The only aparent diference between the two is that the first one selects the field “CobroV”.“NumRecibo” while the second one does not.
Any Idea on how I can make this query work?