Little Help from Query Gurus, please.
Posted: Sat Oct 10, 2015 10:44 am
October 10, 2015
Hello to y'all query gurus.
Every time I try something fancy, I get stuck. Well not every time but enough times to make it feel that way.
Here's one of our standard queries that I have tweaked a bit to provide very useful information. Now I would
like to add in information from 'paysplit table.'
Here is the original query:
/*995 Modified 2015-09-25 for Dr. Smith's recapitulation of dental insurance payments ....
ProcDate, Provider, Clinic, ProcCode, Fee, and InsPayEst for completed procedures in a date range of a specific provider and carrier.*/
/*Query code written/modified 08/14/2015*/
SET @StartDate = '2015-01-01', @EndDate = '2015-09-26'; #Set date range here
SET @ProvNum = 27, @CarrierName = '%%'; #set providerNum and CarrierName here.
SELECT procedurelog.ProcDate, provider.Abbr AS 'ProvAbbr', clinic.Description AS 'Clinic',
procedurecode.ProcCode, claimproc.PlanNum, claimproc.PatNum, DateCP, Status,
/* '0' is sent but not received, '1' is send AND received. */
claimproc.ProcNum, procedurelog.ProcFee*(procedurelog.UnitQty+procedurelog.BaseUnits) AS 'ProcFee',
SUM(claimproc.InsPayEst) AS 'InsPayEst', InsPayAmt, Remarks
FROM procedurelog
INNER JOIN claimproc ON procedurelog.ProcNum=claimproc.ProcNum
AND claimproc.Status IN (0,1,4,5,6,7,8)
INNER JOIN insplan ON insplan.PlanNum = claimproc.PlanNum
INNER JOIN carrier ON carrier.CarrierNum = insplan.CarrierNum
AND carrier.CarrierName LIKE @CarrierName
INNER JOIN procedurecode ON procedurelog.CodeNum = procedurecode.CodeNum
LEFT JOIN clinic ON clinic.ClinicNum=procedurelog.ClinicNum
INNER JOIN provider ON provider.ProvNum=claimproc.ProvNum
AND provider.ProvNum = @ProvNum
WHERE procedurelog.ProcDate BETWEEN @StartDate AND @EndDate
AND procedurelog.ProcStatus = 2 #complete
GROUP BY procedurelog.ProcNum
ORDER BY ProcDate;
So, now I want to add in information for paysplit.
SELECT * FROM paysplit
ORDER BY ProcDate DESC;
Basically, The top query can provide Dr. Smith with the information as to what he has generated (produced), what has been billed for, and what we have collected on his behalf for insurance patients within a given week, or month or year.
If I add in paysplit information, then I will have the above information for cash, credit card, CareCredit, or those paying for their treatment in bushels of corn, or pumpkins. If you can give me sentence or two about your logic about which JOINS to use, that too would be helpful so I can eventually learn SQL on my own.
So thanks in advance query gurus. Thank you very much.
Regards,
Joely
PS~ To comply with HIPAA regulations, I have changed the doctor's name to Dr. Smith. That is not his real name. His real name is Dr. Jones.
Hello to y'all query gurus.
Every time I try something fancy, I get stuck. Well not every time but enough times to make it feel that way.
Here's one of our standard queries that I have tweaked a bit to provide very useful information. Now I would
like to add in information from 'paysplit table.'
Here is the original query:
/*995 Modified 2015-09-25 for Dr. Smith's recapitulation of dental insurance payments ....
ProcDate, Provider, Clinic, ProcCode, Fee, and InsPayEst for completed procedures in a date range of a specific provider and carrier.*/
/*Query code written/modified 08/14/2015*/
SET @StartDate = '2015-01-01', @EndDate = '2015-09-26'; #Set date range here
SET @ProvNum = 27, @CarrierName = '%%'; #set providerNum and CarrierName here.
SELECT procedurelog.ProcDate, provider.Abbr AS 'ProvAbbr', clinic.Description AS 'Clinic',
procedurecode.ProcCode, claimproc.PlanNum, claimproc.PatNum, DateCP, Status,
/* '0' is sent but not received, '1' is send AND received. */
claimproc.ProcNum, procedurelog.ProcFee*(procedurelog.UnitQty+procedurelog.BaseUnits) AS 'ProcFee',
SUM(claimproc.InsPayEst) AS 'InsPayEst', InsPayAmt, Remarks
FROM procedurelog
INNER JOIN claimproc ON procedurelog.ProcNum=claimproc.ProcNum
AND claimproc.Status IN (0,1,4,5,6,7,8)
INNER JOIN insplan ON insplan.PlanNum = claimproc.PlanNum
INNER JOIN carrier ON carrier.CarrierNum = insplan.CarrierNum
AND carrier.CarrierName LIKE @CarrierName
INNER JOIN procedurecode ON procedurelog.CodeNum = procedurecode.CodeNum
LEFT JOIN clinic ON clinic.ClinicNum=procedurelog.ClinicNum
INNER JOIN provider ON provider.ProvNum=claimproc.ProvNum
AND provider.ProvNum = @ProvNum
WHERE procedurelog.ProcDate BETWEEN @StartDate AND @EndDate
AND procedurelog.ProcStatus = 2 #complete
GROUP BY procedurelog.ProcNum
ORDER BY ProcDate;
So, now I want to add in information for paysplit.
SELECT * FROM paysplit
ORDER BY ProcDate DESC;
Basically, The top query can provide Dr. Smith with the information as to what he has generated (produced), what has been billed for, and what we have collected on his behalf for insurance patients within a given week, or month or year.
If I add in paysplit information, then I will have the above information for cash, credit card, CareCredit, or those paying for their treatment in bushels of corn, or pumpkins. If you can give me sentence or two about your logic about which JOINS to use, that too would be helpful so I can eventually learn SQL on my own.
So thanks in advance query gurus. Thank you very much.
Regards,
Joely
PS~ To comply with HIPAA regulations, I have changed the doctor's name to Dr. Smith. That is not his real name. His real name is Dr. Jones.