sql server - Group by or aggregate error even though field is included in group by list -


i have sql multiple value grouping query in want find maximum of field slt.outcost. running results in following error:

column '#eldekiseri.code' invalid in select list because not contained in either aggregate function or group clause."

i error though field included in group by clause.

if delete max aggregate , include slt.outcost in group list, error goes away can't find maximum field anymore.

this sql:

set @sqlabuk = ' select eldekiseri.code [serİ no],  eldekiseri.kodu [stok kodu], eldekiseri.aciklama [stok adi], clc.code [carİ kod],  clc.definition_ [carİ adi], max(slt.outcost) [aliŞ fİyati], stf.date_ [aliŞ tarİhİ], eldekiseri.ambarno [Şube kodu] '+@firmdb+'.dbo.lg_'+@firmnumber+'_'+@firmperiod+'_serilotn sl inner join '+@firmdb+'.dbo.lg_'+@firmnumber+'_'+@firmperiod+'_sltrans slt on sl.logicalref = slt.slref inner join #eldekiseri eldekiseri on sl.code = eldekiseri.code inner join '+@firmdb+'.dbo.lg_'+@firmnumber+'_'+@firmperiod+'_stfiche stf on slt.stficheref = stf.logicalref inner join '+@firmdb+'.dbo.lg_'+@firmnumber+'_clcard clc on stf.clientref = clc.logicalref (slt.invenno = 0) , (slt.fichetype = 1)'; --print @sqlabuk; --exec (@sqlabuk); set @sqlabuk = @sqlabuk +' , eldekiseri.code not in ( select distinct bc.[serİ no] #birlestirilmisclone bc ) '; set @sqlabuk = @sqlabuk +' group eldekiseri.code, eldekiseri.kodu, eldekiseri.aciklama, clc.code, clc.definition_, stf.date_, eldekiseri.ambarno'; set @sqlabuk = @sqlabuk +' order eldekiseri.code, eldekiseri.kodu, eldekiseri.aciklama, clc.code, clc.definition_, slt.outcost, stf.date_, eldekiseri.ambarno'; print @sqlabuk; --exec(@sqlabuk); insert #birlestirilmis exec(@sqlabuk); --print (@sqlabuk); 

it because have slt.outcost in order clause. remove , rid of error.


Comments