I need some assistance with the below mentioned code. Essentially what I need to do is insert a new row for an off-setting A/R account.
For Example, I will have two rows (one for the charge and one for the adjustment each related by the PatientVisitId (distinct and primary key)). An example of this would look like this minus a lot of my fields, but to give you a fast visual:
Charge: Credit = $225.00, Debit = $0.00
Adjustment: Credit = $0.00, Debit = $65.00
What I need is a new row for the difference.
In this instance, I would get a new row "A/R" with a Credit = $0.00, Debit = $160.00 ($225.00 charge minus $65.00 adjustment).
SET NOCOUNT ON
; WITH CTE AS
--- Bring in the Charges
'Charge' AS [Type],
b.[Entry] AS BatchEntry,
'100' AS [Fund],
LEFT(ISNULL(fin.Ledger , '') , 5)AS [GL#],
LEFT(ISNULL(fac.Ledger , '') , 4)AS [Prog],
LEFT(ISNULL(ic.Ledger , '') , 4) AS [Srce],
'' AS [Func], --- Need case statement here for Place Of Service
LEFT(ISNULL(doc.Ledger , '') , 4)AS [EE],
'99999' AS [Seg 1],
'99999' AS [Seg 2],
0.0 AS [Debit],
SUM(pvp.totalfee) AS [Credit],
ISNULL(ic.ListName,'Self') + SPACE(2) + fac.ListName + SPACE(2) + 'A/R' AS [Description]
INNER JOIN DoctorFacility comp ON pv.Compa
View Complete Post