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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 The multi-part identifier could not be bound

Author  Topic 

JeffS23
Posting Yak Master

212 Posts

Posted - 2009-01-05 : 14:25:59
I am looking to report back visits with offsetting patient credits with patient debits. I want to first query all visits that have a patient credit balance. Then I want to see if the patient has an off-setting debit somewhere on another patientvisitId (this could be more then one visit). The balance must equal $0.00 for the patients visits to be pulled back into my report.

Ultimately this is what I want to see back in my result set.

Joe Patient - DOS 01/01/2009 - ($5.00) Credit

Joe Patient - DOS 02/01/2009 - $2.50 Debit

Joe Patient - DOS 04/01/2009 - $2.50 Debit

Net result for Credits owed plus Debits owed = $0.00. This would enable my client to convey the funds from the credit visit(s) over to the visit(s) with the debit.

Currently with the code below, I am getting this back in SQL:

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "ppa.PatBalance" could not be bound.


WITH PPV
AS (
SELECT
pp.PatientId ,
pp.PatientProfileID ,
pv.PatientVisitId ,
pv.TicketNumber ,
ISNULL(CONVERT(VARCHAR(20) , pv.visit , 101) , '') AS [DateOfService] ,
pva.PatBalance
FROM
PatientVisit pv
INNER JOIN PatientProfile pp ON pv.PatientProfileId = pp.PatientProfileId
INNER JOIN PatientVisitAgg pva ON pv.PatientVisitId = pva.PatientVisitId
)
SELECT
PVCB.* ,
dbo.FormatName(pp.Prefix , pp.First , pp.Middle , pp.Last , pp.Suffix) AS [Patient Name] ,
ppa.PatBalance AS [Total Patient Balance]
FROM
(
SELECT * FROM PPV WHERE ppv . Patbalance < 0
) AS PVCB --visits with credit bal
INNER JOIN (
SELECT * FROM PPV WHERE ppv . Patbalance > 0
) AS PVDB --visits with debit bal
ON PVCB.PatientID = PVDB.PatientID
INNER JOIN PatientProfile pp ON pp.PatientId = pvcb.PatientId

revdnrdy
Posting Yak Master

220 Posts

Posted - 2009-01-05 : 14:34:57

Well,

whats the difference between ppa.PatBalance and ppv.PatBalance?
Is this a syntax error?

Is there a ppa.PatBalance in table PPV?
Go to Top of Page
   

- Advertisement -