Msg 8120, Level 16, State 1, Line 1 Column 'tblDailyReceipts.CustomerName' is invalid in the select

Posted by Vanchi050585 under Sql Server on 8/30/2010 | Points: 10 | Views : 21306 | Status : [Member] | Replies : 2
hi all,
i write a query like below:

select TransactionNo,CustomerName,Date,LoanAmount,TotalAmount,DailyInterest,Sum(DailyInterest) as RecdInt from tblDailyReceipts where Date between '02-08-2010' and '30-08-2010' and TransactionNo='8' group by TransactionNo

but the below error was displayed.

Msg 8120, Level 16, State 1, Line 1
Column 'tblDailyReceipts.CustomerName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

pls anyone tell me the mistake and explain when this problem will occur.

Thanks

Thanks
tvn



Responses

Posted by: Peermohamedmydeen on: 8/30/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi,

You have used an aggregate function Sum(DailyInterest). So you should use CustomerName in group by Clause.

Thanks
PMM :)

Vanchi050585, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: PandianS on: 8/30/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi

Whenever you use aggregate with SELECT, Give all the Columns (Available in SELECT statement) in GROUP BY except the aggregated column.

ie:
Select TransactionNo,CustomerName,[Date],LoanAmount,TotalAmount,DailyInterest,Sum(DailyInterest) as RecdInt from tblDailyReceipts where [Date] between '02-08-2010' and '30-08-2010' and TransactionNo='8' group by TransactionNo,CustomerName,[Date],LoanAmount,TotalAmount,DailyInterest

Cheers

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Vanchi050585, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response