gpt4 book ai didi

SQL 存储过程不返回任何数据

转载 作者:行者123 更新时间:2023-12-04 21:12:25 24 4
gpt4 key购买 nike

当我在这个表上运行一个简单的 SELECT 语句时,我得到了一行(这是正确的,应该只有一个)。这是 SELECT 语句:

select * from Lending.HMDA where BatchId = 1

这是我正在执行的过程,它不返回任何行:

    DECLARE @BatchStartDate datetime, @BatchEndDate datetime

SELECT @BatchStartDate = StartDate, @BatchEndDate = EndDate FROM Lending.HMDAReportBatch WHERE BatchId = 1

-- HMDA And App Data
SELECT
A.ApplicationId,
A.CreatedDate,
LU14.LookupCode AS LoanTypeId,
LU1.LookupCode AS PropertyTypeId,
LU2.LookupCode AS LoanPurposeId,
LU3.LookupCode AS OwnerOccupancyId,
L.FinalLoanAmount,
LU4.LookupCode AS PreApprovalId,
LU5.LookupCode AS ActionId,
A.ActionDate,
H.MSA,
LU6.MiscCode1 AS StateId,
LU7.LookupCode AS CountyId,
H.CensusTract,
LU8.LookupCode AS ApplicantEthnicityId,
LU9.LookupCode AS JointEthnicityId,
H.IsApplicantRaceAmericanIndian,
H.IsApplicantRaceAsian,
H.IsApplicantRaceBlack,
H.IsApplicantRaceIslander,
H.IsApplicantRaceNA,
H.IsApplicantRaceNotProvided,
H.IsApplicantRaceWhite,
H.IsJointRaceAmericanIndian,
H.IsJointRaceAsian,
H.IsJointRaceBlack,
H.IsJointRaceIslander,
H.IsJointRaceNA,
H.IsJointRaceNotProvided,
H.IsJointRaceWhite,
LU10.LookupCode AS ApplicantGenderId,
LU11.LookupCode AS JointGenderId,
LU12.LookupCode AS LoanPurchaserId,
H.IsDenialReasonCash,
H.IsDenialReasonCollateral,
H.IsDenialReasonCreditHistory,
H.IsDenialReasonDTI,
H.IsDenialReasonEmploymentHistory,
H.IsDenialReasonIncomplete,
H.IsDenialReasonInverifiableInfo,
H.IsDenialReasonMortgageInsuranceDenied,
H.IsDenialReasonOther,
H.RateSpread,
H.IsHOEPA,
LU13.LookupCode AS LienStatusId
--@BatchStartDate AS BatchStartDate,
--@BatchEndDate AS BatchEndDate
FROM Lending.HMDA H
INNER JOIN Lending.Application A ON H.ApplicationId = A.ApplicationId
INNER JOIN Lending.Loan L ON H.ApplicationId = L.ApplicationId
INNER JOIN tblLookup AS LU1 ON H.PropertyTypeId = LU1.LookupID
INNER JOIN tblLookup AS LU2 ON H.LoanPurposeId = LU2.LookupID
INNER JOIN tblLookup AS LU3 ON H.OwnerOccupancyId = LU3.LookupID
INNER JOIN tblLookup AS LU4 ON H.PreApprovalId = LU4.LookupID
INNER JOIN tblLookup AS LU5 ON H.ActionId = LU5.LookupID
INNER JOIN tblLookup AS LU6 ON H.StateId = LU6.LookupID
INNER JOIN tblLookup AS LU7 ON H.CountyId = LU7.LookupID
INNER JOIN tblLookup AS LU8 ON H.ApplicantEthnicityId = LU8.LookupID
INNER JOIN tblLookup AS LU9 ON H.JointEthnicityId = LU9.LookupID
INNER JOIN tblLookup AS LU10 ON H.ApplicantGenderId = LU10.LookupID
INNER JOIN tblLookup AS LU11 ON H.JointGenderId = LU11.LookupID
INNER JOIN tblLookup AS LU12 ON H.LoanPurchaserId = LU12.LookupID
INNER JOIN tblLookup AS LU13 ON H.LienStatusId = LU13.LookupID
INNER JOIN tblLookup AS LU14 ON H.LoanTypeId = LU14.LookupID

WHERE H.BatchId = 1 AND H.IsExcluded <> 'True'

为什么 proc 没有返回任何数据?发生这种情况的可能情况是什么?

最佳答案

如果 on 条件匹配,inner join 只会返回一行。尝试将它们全部更改为 left outer join 并查看是否得到任何行。

left join 中,当 on 条件不匹配时,表的列将为 null。这通常是找到有问题的表的快速方法。

关于SQL 存储过程不返回任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3388190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com