jchewsmith
Technical User
I need to return a value from a subquery where a field in the main query is joining on a field in the subquery.
Main Query has Loan#, DocTypeName, CreatedDate
SubQuery has Loan#, CancelDate
I need results to return Loan#, CreatedDate, DocTypeName from main query and CancelDate from SubQuery where Loan# matches and the subquery is based off of more than one table already
Here is my subquery:
SELECT LEFT(Loan.sLNm, 6) AS Loan#, Status.sCanceledD AS [CancelInfo]
FROM Agents AS Agents INNER JOIN
Originating_Company AS Originating_Company ON Agents.sPmlBrokerId = Originating_Company.PmlBrokerId RIGHT OUTER JOIN
Loan AS Loan ON Agents.sLId = Loan.sLId LEFT OUTER JOIN
Status AS Status ON Loan.sLId = Status.sLId
WHERE (Status.sCanceledD IS NOT NULL) AND (Loan.sLpTemplateNm = 'Easy Close') AND (Status.sStatusT IN (9, 10, 49))
Here is my Query:
SELECT Loan.sLNm AS Loan#, EDoc.DocTypeName, EDoc.CreatedDate
FROM
Loan AS Loan_1 INNER JOIN
Status AS Status_1 ON Loan_1.sLId = Status_1.sLId RIGHT OUTER JOIN
Agents AS Agents INNER JOIN
Originating_Company AS Originating_Company ON Agents.sPmlBrokerId = Originating_Company.PmlBrokerId RIGHT OUTER JOIN
Loan AS Loan ON Agents.sLId = Loan.sLId LEFT OUTER JOIN
Status AS Status ON Loan.sLId = Status.sLId LEFT OUTER JOIN
EDoc AS EDoc ON Loan.sLId = EDoc.sLId ON LEFT(Loan_1.sLNm, 6) = Loan.sLNm
WHERE (Loan_1.sLpTemplateNm = 'Capital Access') AND (Loan.sLienPosT = 0) AND (Loan_1.sLienPosT = 1) AND (NOT (Status_1.sStatusT IN (9, 10))) AND (EDoc.IsValid = 1) AND (EDoc.DocTypeName LIKE 'sub%') AND
(Originating_Company.Name NOT LIKE 'test%') AND (NOT (Status.sStatusT IN (9, 49))
Main Query has Loan#, DocTypeName, CreatedDate
SubQuery has Loan#, CancelDate
I need results to return Loan#, CreatedDate, DocTypeName from main query and CancelDate from SubQuery where Loan# matches and the subquery is based off of more than one table already
Here is my subquery:
SELECT LEFT(Loan.sLNm, 6) AS Loan#, Status.sCanceledD AS [CancelInfo]
FROM Agents AS Agents INNER JOIN
Originating_Company AS Originating_Company ON Agents.sPmlBrokerId = Originating_Company.PmlBrokerId RIGHT OUTER JOIN
Loan AS Loan ON Agents.sLId = Loan.sLId LEFT OUTER JOIN
Status AS Status ON Loan.sLId = Status.sLId
WHERE (Status.sCanceledD IS NOT NULL) AND (Loan.sLpTemplateNm = 'Easy Close') AND (Status.sStatusT IN (9, 10, 49))
Here is my Query:
SELECT Loan.sLNm AS Loan#, EDoc.DocTypeName, EDoc.CreatedDate
FROM
Loan AS Loan_1 INNER JOIN
Status AS Status_1 ON Loan_1.sLId = Status_1.sLId RIGHT OUTER JOIN
Agents AS Agents INNER JOIN
Originating_Company AS Originating_Company ON Agents.sPmlBrokerId = Originating_Company.PmlBrokerId RIGHT OUTER JOIN
Loan AS Loan ON Agents.sLId = Loan.sLId LEFT OUTER JOIN
Status AS Status ON Loan.sLId = Status.sLId LEFT OUTER JOIN
EDoc AS EDoc ON Loan.sLId = EDoc.sLId ON LEFT(Loan_1.sLNm, 6) = Loan.sLNm
WHERE (Loan_1.sLpTemplateNm = 'Capital Access') AND (Loan.sLienPosT = 0) AND (Loan_1.sLienPosT = 1) AND (NOT (Status_1.sStatusT IN (9, 10))) AND (EDoc.IsValid = 1) AND (EDoc.DocTypeName LIKE 'sub%') AND
(Originating_Company.Name NOT LIKE 'test%') AND (NOT (Status.sStatusT IN (9, 49))