在这方面需要帮助。
我只是想知道为什么会发生这个错误。下面是相关的脚本。
SELECT loc.ID
,loc.LocCode
,loc.LocName
,st.StateName
,reg.RegionName
,ctry.CountryName
,ISNULL(CONVERT(DATE, loc.UpdatedDate), CONVERT(DATE,loc.CreatedDate)) AS [ModifiedDate]
,stf.Name AS [ModifiedBy]
FROM Spkr_Country AS ctry WITH (NOLOCK)
INNER JOIN Spkr_Location AS loc WITH (NOLOCK) ON ctry.ID = loc.CountryID
INNER JOIN Spkr_State AS st WITH (NOLOCK) ON loc.StateID = st.ID
INNER JOIN Spkr_Region AS reg WITH (NOLOCK) ON loc.RegionID = reg.ID
INNER JOIN Staff AS stf ON ISNULL(loc.UpdatedBy, loc.CreatedBy) = stf.StaffId
WHERE (loc.IsActive = 1)
AND (
(@LocCode = '')
OR (
@LocCode <> ''
AND loc.LocCode LIKE @LocCode + '%'
)
)
AND (
(@RegionID < 1)
OR (
@RegionID > 0
AND loc.RegionID = @RegionID
)
)
AND (
(@StateID < 1)
OR (
@StateID > 0
AND loc.StateID = @StateID
)
)
AND (
(@CountryID < 1)
OR (
@CountryID > 0
AND loc.CountryID = @CountryID
)
)
错误可能发生在这里INNER JOIN Staff AS stf ON ISNULL(loc.UpdatedBy, loc.CreatedBy) = stf.StaffId
我想要的要求是如果loc.UpdatedBy
为null,它将使用该loc.CreatedBy
列。但是,当我使用它时,它会产生提到的错误。
在数据库中,loc.CreatedBy
不为空,而 可以loc.UpdatedBy
为空。
我通过运行脚本检查了它,但它工作正常。
我该怎么办?我的代码有什么问题?请帮忙。