错误71561:对对象的未解析引用

问题描述 投票:0回答:1

在Visual Studio 2017,SSDT 2015中,我收到“对象的未解析引用”错误。该错误发生了2589次,因此对于一个特定的代码段而言,这不是问题。所有代码都可以编译并直接在SQL Server中运行。

我已经尝试了this中的所有内容,但由于已删除“针对通用对象的扩展Transact-SQL验证”,因此已禁用该选项。

我已经尝试了几乎可以在Google上找到的所有其他内容;我已经为此努力了两天。

这里是一些出现错误的代码的示例。它可以直接在SQL Server上正常运行。该错误出现在包含数据库引用的每一行的FROM子句中。我无法删除这些引用或更改视图的位置。在引用视图的存储过程中也会发生这种情况。

CREATE view [Migration].[vwCHILDS_Allegation_AllegationTrackingCharacteristics]
as
with src as (
    select
        (select AllegationId from CWNS_Migration.Allegation.Allegation where SourceSystemId = cast(1 as int) and SourceSystemIdentifier = cast(a.IDNBR as nvarchar(64))) AllegationId
        , (select TrackingCharacteristicsId from CWNS_Migration.Allegation.TrackingCharacteristics where Code = dfrvmi1.DestinationDataFieldReferenceValueCode) TrackingCharacteristicsId
        , (select VerificationStatusId from CWNS_Migration.Allegation.VerificationStatus where Code = dfrvmi2.DestinationDataFieldReferenceValueCode) VerificationStatusId
        , cast(1 as int) SourceSystemId
        , cast(src.IDNBR as nvarchar(64)) SourceSystemIdentifier
        , src.IDNBR SourceSystemIdentifier_Numeric
        , case when src.CRET_DT_TM = '0001-01-01' then null else src.CRET_DT_TM end SourceSystemCreatedDateTime
        , (
            select
                max(pe.PersonId) 
            from
                CWNS_Migration.PersonIdentity.PersonIdentifier pe
                join CHILDSDB2.VLCHA.STAFF_USERID st on cast(st.FK_STAFFFK_PERSID as nvarchar(64)) = pe.Identifier
                    and pe.PersonIdentificationSystemId = 4
            where
                st.USERID = ltrim(rtrim(src.CRET_USER_ID))) SourceSystemCreatedPersonId
    from
        CHILDSDB2.VLCHA.RPT_TRKNG_CHAR src
        join CHILDSDB2.VLCHA.ALGTN a on a.FK_RPTRPT_NBR = src.FK_RPTRPT_NBR
        join CHILDSDB2.VLCHA.FINDING f on f.FK_ALGTNID = a.IDNBR
        join DataCatalog.dbo.DataFieldReferenceValueMappingInfo dfrvmi1 on dfrvmi1.SourceDataFieldReferenceValueDataFieldId = 5438
            and dfrvmi1.SourceDataFieldReferenceValueCode = src.FK_TRKNG_CHAR_TCD
            and dfrvmi1.DestinationDataFieldReferenceValueDataFieldId = 20586
        join DataCatalog.dbo.DataFieldReferenceValueMappingInfo dfrvmi2 on dfrvmi1.SourceDataFieldReferenceValueDataFieldId = 1775
            and dfrvmi2.SourceDataFieldReferenceValueCode = f.FINDING_DET_CD
            and dfrvmi2.DestinationDataFieldReferenceValueDataFieldId = 55983
)
select
    src.*
from
    src
    left join CWNS_Migration.Allegation.AllegationTrackingCharacteristics tgt on tgt.SourceSystemId = src.SourceSystemId and tgt.SourceSystemIdentifier = src.SourceSystemIdentifier
    left join CWNS_Migration.Quarantine.AllegationTrackingCharacteristics q on q.SourceSystemId = src.SourceSystemId and q.SourceSystemIdentifier = src.SourceSystemIdentifier
        and q.QExecutionId = 1
where
    q.QExecutionId is null
    and (
        isnull(src.AllegationId, 0) <> isnull(tgt.AllegationId, 0)
        or isnull(src.TrackingCharacteristicsId, 0) <> isnull(tgt.TrackingCharacteristicsId, 0)
        or isnull(src.VerificationStatusId, 0) <> isnull(tgt.VerificationStatusId, 0)
        or try_cast(isnull(src.SourceSystemCreatedDateTime, '') as datetime) <> isnull(tgt.SourceSystemCreatedDateTime, '')
        or isnull(src.SourceSystemCreatedPersonId, '') <> isnull(tgt.SourceSystemCreatedPersonId, '')
    );
visual-studio sql-server-data-tools
1个回答
0
投票

向项目添加Database reference

您将需要重构代码才能使用:

[$(*ReferencedDatabaseName*)].schemaName.tableName
© www.soinside.com 2019 - 2024. All rights reserved.