日期:2014-05-18 浏览次数:20470 次
--已经很简单了,没法再优化 --唯一能优化的就是函数内部的查询了,楼主把函数内部查询贴出来吧 select * from employee e cross apply dbo.Fa(e.departmentID)
------解决方案--------------------
try
declare @sql varchar(8000) select @sql=isnull(@sql+' union all ','') +' select * from dbo.Fa('+ltrim(departmentID)+')' from (select distinct departmentID from employee) t set @sql='select * from employee a left join ('+@sql+') b on a.departmentID=b.departmentID' exec (@sql)