“无法绑定多部分标识符”更新语句从“内部”设置为“更新”设置

问题描述

错误

'无法绑定多部分标识符“ar_update.Id”。'

作为 sql 脚本中表示的行。

我还为错误连接尝试了其他列,尝试提示不同的错误并给出相同的错误结果。

为什么/如何将“内部”处理集限定回“更新”集?

update ar_update 
   set ar_update.[GLEntry_Amount] = ar_sum.[GLEntry_Amount_sum]
  from [dbo].[ASL_Result_vgo]  as ar_update  

  join (select  ar.[Id]                        as [Id],ar.[Company Id]                as [Company Id],ar.[Schedule Name]             as [Schedule Name],ar.[Line No_]                  as [Line No_],ar.[Row No_]                   as [Row No_],ar.[Posting Date]              as [Posting Date],ar.[Business Centre Code]      as [Business Centre Code],ar.[Site Locations Code]       as [Site Locations Code],GLEntry_Amount_sum = 
                    (select  sum(are.[GLEntry_Amount])     
                     from    [dbo].[ASL_Result_vgo]  as are
                     where   are.[Company Id]           = ar.[Company Id]  and          
                             are.[Schedule Name]        = ar.[Schedule Name]  and       
                             are.[Posting Date]         = ar.[Posting Date]  and          
                             are.[Business Centre Code] = ar.[Business Centre Code]  and   
                             are.[Site Locations Code]  = ar.[Site Locations Code]  and 
                             are.[Row No_] in ( select * from dbo.udf_range_expand_vgo(ar.[Totaling]) )  
                    )

        from    [dbo].[ASL_Result_vgo]  as ar
        where   ar.[Id] = ar_update.[Id]    -- The multi-part identifier "ar_update.Id" Could not be bound.  

       )  ar_sum  on  ar_update.[Id] = ar_sum.[Id]           

    where   ar_update.[Totaling Type] = 2  and   -- formulas
            len(trim(ar_update.[Totaling])) > 0  and      
            charindex('..',ar_update.[Totaling]) > 0   -- P ranges

解决方法

发生这种情况是因为在 where ar.[Id] = ar_update.[Id] 上,因为 ar_update.[Id] 不是一个值,它是一个多值类型,就像你在比较一个列表和一个整数,试试这个

update ar_update 
   set ar_update.[GLEntry_Amount] = ar_sum.[GLEntry_Amount_sum]
  from [dbo].[ASL_Result_VGO]  as ar_update  

  join (select  ar.[Id]                        as [Id],ar.[Company Id]                as [Company Id],ar.[Schedule Name]             as [Schedule Name],ar.[Line No_]                  as [Line No_],ar.[Row No_]                   as [Row No_],ar.[Posting Date]              as [Posting Date],ar.[Business Centre Code]      as [Business Centre Code],ar.[Site Locations Code]       as [Site Locations Code],GLEntry_Amount_sum =     (select  sum(are.[GLEntry_Amount])     
                     from    [dbo].[ASL_Result_VGO]  as are
                     where   are.[Company Id]           = ar.[Company Id]  and          
                             are.[Schedule Name]        = ar.[Schedule Name]  and       
                             are.[Posting Date]         = ar.[Posting Date]  and          
                             are.[Business Centre Code] = ar.[Business Centre Code]  and   
                             are.[Site Locations Code]  = ar.[Site Locations Code]  and 
                             are.[Row No_] in ( select * from dbo.udf_range_expand_VGO(ar.[Totaling]) )  
                    )

        from    [dbo].[ASL_Result_VGO]  as ar
 

       )  ar_sum  on  ar_update.[Id] = ar_sum.[Id]           

    where   ar_update.[Totaling Type] = 2  and   -- formulas
            len(trim(ar_update.[Totaling])) > 0  and      
            charindex('..',ar_update.[Totaling]) > 0