sql - Column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause -


i'm trying select bunch of patients unit , division , want group result unit name, code doesn't execute , gives error topic of question.

select top (100) percent      pat.patname name,      srvdiv.sgmtype perkhidmatan,     pat.patmrank pangkat,      pat.patmilitaryid [no# tentera],     unt.untname unit,     fct.pesstatuscode statuscode,     fct.pessigneddate signeddate  dbo.factpes fct inner join      dbo.dimpatient pat on fct.pespatid = pat.patid left outer join     dbo.dimunit unt on fct.pesunitid = unt.untid left outer join      dbo.dimservicediv srvdiv on fct.pesservicedivid = srvdiv.sgid  group unt.untname having (deas.didate between       convert(datetime, @fromdate, 102)  ,      convert(datetime, @todate, 102)) 

i assume it's because unt.untname in left join can't use outside join maybe ? i'm bit confused because when put works:

group unt.untname, pat.patname, srvdiv.sgmtype,      pat.patmrank, pat.patmilitaryid, unt.untname,      fct.pesstatuscode, fct.pessigneddate 

any appreciated

first, please don't use top (100) percent; hurts read.

second, query contains no aggregate function, no sum or count example. when want "group unit name", suspect may want results sorted unit name. in case, want order by instead. (the advice other study group by taken.)

finally, might not need convert functions @ end, depending on dbms.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -