添加到以前工作的查询后SUM(b.[Amount_withDiscount])
,我收到选择查询的以下错误。inner join on tables
现在我希望查询也返回相关表中该列的总和。我哪里出错了?
您尝试执行的查询不包含指定表达式 'p.[PFirstName] & ' ' & p.[PLastName]' 作为聚合函数的一部分。
工作查询
string sql = "SELECT p.[PFirstName]&' '&p.[PLastName] as [Patient Name],p.[Age],p.[BirthDate],p.[MobileNo]&' / '&p.[LandlineNo] as [Contact Number] FROM Patient_Registration p WHERE datepart('m',p.[RegDate])=@month AND datepart('yyyy',p.[RegDate])=@year AND p.DoctorID=" + drId;
加总和内连接后查询
string sql = "SELECT p.[PFirstName]&' '&p.[PLastName] as [Patient Name],p.[Age],p.[BirthDate],p.[MobileNo]&' / '&p.[LandlineNo] as [Contact Number], SUM(b.[Amount_withDiscount]) as [Payable Amount] FROM Patient_Registration p INNER JOIN Bill_Master b on p.[PatientID]=b.[Patient_ID] WHERE datepart('m',p.[RegDate])=@month AND datepart('yyyy',p.[RegDate])=@year AND p.DoctorID=" + drId;