Ahmad
Ahmad

Reputation: 55

Sub Query Alias in Group By Not Working Invalid Columns ERROR

I am using a sub query in a sql query. but unfortunately when i try to use it in group by column i am getting INVALID COLUMN error. what is solution?

enter image description here

Upvotes: 1

Views: 852

Answers (1)

Vecchiasignora
Vecchiasignora

Reputation: 1315

You dont need to read tbl_AccountLedger data again in select clause, because you already have it by joins(by same connection/condition), just replace your (select......) ll part with l.ledgerName like this

select l.ledgerName, sum(m.debit), sum (m.credit),
  from tbl_LedgerPosting  as m 
   left join [dbo].[tbl_VoucherType] as v on m.voucherTypeId=v.voucherTypeId
   left join [dbo].[tbl_AccountLedger] as l on m.ledgerId=l.ledgerId
group by v.coucherTypeName, m voucherNo, l.ledgerName
order by v.coucherTypeName, m voucherNo

Upvotes: 3

Related Questions