Question : Help with a SQL Join

First and foremost, the SQL is handled dynamically by the SQL Server, therefore items in my WHERE clause will look odd to you, please disregard them. What I need help with is my JOIN on the Transactions table. I need it to only pull back when Type = P for Payments and when the Payment Type = 'HSN Recovery'.

Any help is deeply appreciated.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
SET NOCOUNT ON

SELECT  
	pp.PatientProfileID,
	pp.PatientID,
	dbo.FormatName(pp.Prefix , pp.First , pp.Middle , pp.Last , pp.Suffix) AS PatientName,
	ISNULL(CONVERT(VARCHAR(20) , pp.birthdate , 101) , '') AS Birthdate,
	pp.Sex,
	ISNULL(cri.FamilySize , '') AS FamilySize,
	CONVERT(MONEY , ISNULL(cri.MonthlyIncome * 12 , 0)) AS Income,
	pv.TicketNumber,
	ISNULL(CONVERT(VARCHAR(20) , pv.Visit , 101) , '') AS Visit,
	d.ListName AS Doctor,
	f.ListName AS Facility,
	c.ListName AS Company, 
	ic.ListName AS Carrier,
	pvp.CPTCode,
	ml.Description AS Qualifier,
	pvp.TotalFee AS Fee, 
	pvp.TotalAllowed AS Allowed,
	SUM(ISNULL(pvp.CalculatedUnits,0)) AS Units,
	SUM(ISNULL(td.Amount,0)) AS Payment

FROM    
	PatientVisit pv
	JOIN PatientProfile pp ON pv.PatientProfileId = pp.PatientProfileId
	JOIN DoctorFacility d ON pv.DoctorId = d.DoctorFacilityId
	JOIN DoctorFacility c ON pv.CompanyId = c.DoctorFacilityId
	JOIN DoctorFacility f ON pv.FacilityId = f.DoctorFacilityId
	LEFT JOIN InsuranceCarriers ic ON pv.PrimaryInsuranceCarriersId = ic.InsuranceCarriersId
	LEFT JOIN PatientVisitProcs pvp ON pv.PatientVisitId = pvp.PatientVisitId
	LEFT JOIN Batch b ON pvp.BatchId = b.BatchId
	LEFT JOIN Procedures p ON pvp.ProceduresId = p.ProceduresId
	LEFT JOIN cusCRIInterview cri ON pp.PatientProfileId = cri.PatientProfileID
	LEFT JOIN MedLists ml ON p.CPTProcedureCodeQualifierMId = ml.MedListsId 
	LEFT JOIN VisitTransactions vt ON pv.PatientVisitId = vt.PatientVisitId
	LEFT JOIN TransactionDistributions td ON td.PatientVisitProcsId = pvp.PatientVisitProcsId
	LEFT JOIN Transactions tc ON vt.VisitTransactionsId = tc.VisitTransactionsId WHERE tc.Type = 'P' AND tc.ActionTypeMId IN (SELECT * FROM medlists WHERE TableName = 'PaymentTypes' AND Description = 'HSN Recovery')

WHERE	
	ISNULL(pvp.Voided,0) = 0 
	AND --Filter on Date Type and Range
	(
	('1' = '1' AND pvp.DateOfServiceFrom >= ISNULL('07/01/2010','1/1/1900') AND pvp.DateOfServiceFrom < dateadd(d, 1, ISNULL('07/27/2010','1/1/3000'))) OR
	('1' = '2' AND pvp.DateOfEntry >= ISNULL('07/01/2010','1/1/1900') AND pvp.DateOfEntry < dateadd(d,1,ISNULL('07/27/2010','1/1/3000')))
	)
	AND  --Filter on Doctor
	(
	(NULL IS NOT NULL AND pv.DoctorID IN (NULL)) OR
	(NULL IS NULL)
	)
	AND  --Filter on Facility
	(
	(NULL IS NOT NULL AND pv.FacilityID IN (NULL)) OR
	(NULL IS NULL)
	)
	AND  --Filter on Company
	(
	(NULL IS NOT NULL AND pv.CompanyID IN (NULL)) OR
	(NULL IS NULL)
	)
	AND  --Filter on Insurance Carrier
	(
	(NULL IS NOT NULL AND pv.PrimaryInsuranceCarriersId IN (NULL)) OR
	(NULL IS NULL)
	)
	AND  --Filter on Filing Type
	(
	(NULL IS NOT NULL AND pv.FilingMethodMId IN (NULL)) OR
	(NULL IS NULL)
	)
	AND  --Filter on CPT Qualifier
	(
	('2664' IS NOT NULL AND p.CPTProcedureCodeQualifierMId IN (2664)) OR
	('2664' IS NULL)
	)
	

GROUP BY 
	pp.PatientProfileId,
	pp.PatientID,
	dbo.FormatName(pp.Prefix , pp.First , pp.Middle , pp.Last , pp.Suffix),
	pp.Birthdate,
	pp.Sex,
	ISNULL(cri.FamilySize , ''),
	CONVERT(MONEY , ISNULL(cri.MonthlyIncome * 12 , 0)),
	pv.TicketNumber,
	ISNULL(CONVERT(VARCHAR(20) , pv.Visit , 101) , ''),
	d.ListName,
	f.ListName,
	c.ListName, 
	ic.ListName,
	pvp.CPTCode,
	ml.Description,
	pvp.TotalFee, 
	pvp.TotalAllowed,
	td.Amount  
        
ORDER BY
	PatientName,
	TicketNumber

Answer : Help with a SQL Join

Hi,

follow those steps below

1) right click on the folder "WebSite" and click on the Property.
2) then click on the security tab and click on the add button
3) Type "aspnet" and click enter
4) you can see "ASP.NET Machine Account"
5) give it full access and click ok.

If till not working then change something in IIS
check ASP.net Vertion
Also set "Application Protection" to "Low (IIS Process)

(see images)


Thanks
Santanu

Random Solutions  
 
programming4us programming4us