sql:update 
aa
set 
aa.FourWeekSaleAVG=avg(td.売上数)

from 
OPENDATASOURCE(
         'SQLOLEDB',
         'Data Source=server;User ID=sa;Password=').ff.td
where 
aa.BranchCode=td.店CD and
td.年週 between @YZs and @YZe
(aa.EntryType=2 and td.JAN=aa.ItemCode) or
(aa.EntryType=4 and td.JAN=aa.ItemCodeOld)
group by
td.JAN,td.店CD报错的时候说,update  的set 里面不能用集合函数,有什么其它的代替方法么?一次就可一个更新进去的,谢谢!!

解决方案 »

  1.   

    tryupdate 
    aa
    set 
    aa.FourWeekSaleAVG=td.売上数

    from 
    aa,
    (Select td.JAN,td.店CD,avg(td.売上数) As 売上数
    From
    OPENDATASOURCE(
             'SQLOLEDB',
             'Data Source=server;User ID=sa;Password=').ff.td
    Where 
    td.年週 between @YZs and @YZe
    group by
    td.JAN,td.店CD) td
    where 
    aa.BranchCode=td.店CD and 
    ((aa.EntryType=2 and td.JAN=aa.ItemCode) or (aa.EntryType=4 and td.JAN=aa.ItemCodeOld))