lundi 2 février 2015

One Query 2 Joins

From my main table, I want to show all applicable dates from the calendar table and only show data that does not exist in the Branch table. This is the query I am trying, but it is returning way more results that it should be. Did I do a join incorrectly? Should I be using a sub-query or CTE instead?



Select
'Master' As [Type],
Main.EmployeeID,
Main.BankName,
Main.BankEmployeeName,
Main.Title,
Main.loan_status,
Cal.[Month],
Cal.[Year],
Main.LoanOfficer
From dbo.Calendar Cal
Inner Join MainBankInformation Main
On Cal.[Month] = Main.LoanMonth
Left Join BranchBankInformation Branch
On Main.EmployeeID = Branch.EmployeeID
And Main.loan_status IN ('approved', 'complete', 'final')

Aucun commentaire:

Enregistrer un commentaire