Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

create rows even if no inner join match

$
0
0

Hi,

I have this sql

select EPSReferralKPIs.dbPatID, EPSReferralKPIs.dbPatLastName, EPSReferralKPIs.dbAddDate, EPSReferralKPIs.LastName,EPSReferralKPIs.dbStaffLastName,
 SUM(epstransactions.LedgerAmount)as Outstanding, 
 (SUM(CASE WHEN epstransactions.LedgerAmount <= 0 THEN   epstransactions.LedgerAmount ELSE NULL END) * -1) as Charges,
 SUM(CASE WHEN epstransactions.LedgerAmount > 0 THEN epstransactions.LedgerAmount ELSE NULL END) as Payments 
 from epstransactions 

inner join EPSReferralKPIs on epstransactions.PatientID = EPSReferralKPIs.dbPatID

group by EPSReferralKPIs.dbPatID, EPSReferralKPIs.dbPatLastName, EPSReferralKPIs.dbAddDate, EPSReferralKPIs.LastName, EPSReferralKPIs.dbStaffLastName

Which brings back any patient detail where the patientID (dbPatID) from the EPSRerreflKPIs table (names and dates) matches the patientID of the EPSTranscations table (amounts). Cool.

What I would like to acheive is where there isn’t a join for the PatientID bewteen the tables to still create a row from the EPSReferralKPIs table (names and dates) and 0.00’s for the other columns (Outstanding, Charges, Payments).

Thanks for any help.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>