读书人

从表值函数更新虚拟表需要从虚拟表传

发布时间: 2013-07-16 22:38:05 作者: rapoo

从表值函数更新虚拟表,需要从虚拟表传参数进去,一直报这个错,求教该怎么写才对?


select acc.yto_sapcode,yas.yto_accountName,yas.yto_account,
0 as qichu,0 as yingshou,0 as threeMonth,0 as sixMonth,0 as twelveMonth,0 as twoYear,0 as threeYear,0 as beforeThreeYear
into #table
from yto_accountsreceivable yas
left join Account acc on yas.yto_account=acc.AccountId
where yas.statecode=0 and acc.StateCode=0 and acc.yto_accounttype=1
group by yas.yto_accountName,yas.yto_account,acc.yto_sapcode

update #table set #table.qichu=fn.qichu,#table.yingshou=fn.yingshou,#table.threeMonth=fn.threeMonth
from dbo.Frensworkz_getCYJzhujichangXY_Report(#table.yto_account,@endDateUTC) as fn


无法绑定由多个部分组成的标识符 "#table.yto_account"。

问:从表值函数更新虚拟表,需要从虚拟表传参数进去,一直报这个错,求教该怎么写才对? 表值函数 虚拟表 SqlServer SQL
[解决办法]

这个语句不可以这么写
update #table
set #table.qichu=fn.qichu,#table.yingshou=fn.yingshou,#table.threeMonth=fn.threeMonth
from dbo.Frensworkz_getCYJzhujichangXY_Report(#table.yto_account,@endDateUTC) as fn

你改为
update #table
set #table.qichu=fn.qichu,#table.yingshou=fn.yingshou,#table.threeMonth=fn.threeMonth
from (select * from #table.yto_account where xxx=@endDateUTC) as fn

[解决办法]

update #table
set #table.qichu=fn.qichu,#table.yingshou=fn.yingshou,#table.threeMonth=fn.threeMonth
from #table cross apply
dbo.Frensworkz_getCYJzhujichangXY_Report(#table.yto_account,@endDateUTC) as fn

改成这样试试
[解决办法]
引用:
Quote: 引用:


update #table
set #table.qichu=fn.qichu,#table.yingshou=fn.yingshou,#table.threeMonth=fn.threeMonth


from #table cross apply
dbo.Frensworkz_getCYJzhujichangXY_Report(#table.yto_account,@endDateUTC) as fn


改成这样试试
可以用呢,我去查查原理!


与表值函数关联需要用 cross apply 或者outer apply

读书人网 >SQL Server

热点推荐