What I'm trying to do is that the query returns me from the value of the numberPurpose column of a data group in the SequentialGarantia column, but depending on the maximum value of > Initial debt .
What I did is:
SELECT numeroSolicitud, secuencialGarantia, max(deudaInicial) FROM #temp_Garantias
GROUP BY secuencialGarantia
Return the error:
The column '# temp_Garanties.numberRequest' in the selection list is not valid, because it is not contained in an aggregate function or in the GROUP BY clause.
I hope you have understood what I need you to help me, regards.