Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sum syntax

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2010-11-03 : 07:37:46
Hi,

I have the following query which works fine, but I want modify it so that when t1.Prac_no is the same value then SUM (dbo.qryGrossAmountPerPractice.GrossAmount), any help please

SELECT DISTINCT 
TOP (100) PERCENT 'GPRD' AS Source, CAST(t4.Oracle_no AS INT) AS Source_Supplier, t2.pay_sort_code, t2.pay_acc_num, t2.post_code,
t2.pay_method, 'GBP' AS Currency, '0' AS Tax_Percentage, t3.ProjectDesc, '01-M0601-3472-000000-000000' AS Expense_Account,
'GPRD' + ' ' + t2.pay_method AS Paygroup, '1-M0601-5501-000000-000000' AS Liability_Account, t1.Prac_no, t2.prac_eid, t2.payee_name,
RIGHT('0000' + '' + CONVERT(nvarchar(20), t1.PaymentRunID), 4) AS PaymentRunID, dbo.qryGrossAmountPerPractice.GrossAmount, t1.ProjectID,
t1.DatePaid
FROM GPRDTech.gprdsql.TblPracDetails AS t2 INNER JOIN
dbo.tblProjectPatients AS t1 ON t2.prac_no = t1.Prac_no INNER JOIN
dbo.tblProjects AS t3 ON t1.ProjectID = t3.ProjectID INNER JOIN
GPRDTech.gprdsql.TblOracleNos AS t4 ON t2.prac_no = t4.Prac_no AND t2.pay_method = t4.Pay_method INNER JOIN
dbo.qryGrossAmountPerPractice ON t1.ProjectID = dbo.qryGrossAmountPerPractice.ProjectID AND
t1.Prac_no = dbo.qryGrossAmountPerPractice.Prac_no INNER JOIN
dbo.tblCurrCommittProj ON t3.ProjectID = dbo.tblCurrCommittProj.Curr_ProjectID AND
t1.PaymentRunID = dbo.tblCurrCommittProj.Curr_CommittedPayRef
WHERE (t3.ProjectStatus = 'true') AND (t1.PaymentRunID IS NOT NULL) AND (t1.DatePaid IS NOT NULL)
ORDER BY t1.Prac_no
   

- Advertisement -