表值函数所用参数为关联表中值,不能查询?TKS!
select b.job,b.gk,Weight from pca a
join ( select job,gk,Weight from dbo.funkk(a.job,a.gk) b on a.Job=b.job and a.GK=b.gk
是不是不能用关联表中的参数?
------解决方案--------------------用 CROSS APPLY 吧, 今天刚学了。
------解决方案--------------------select b.job,b.gk,Weight,dbo.funkk(a.job,a.gk from pca a
------解决方案--------------------cross apply
cross apply
------解决方案-------------------- select a.* from pcArrangeMain a
cross apply dbo.funkk(a.job_no,a.gk_no) as b on a.Job_No=b.job_no and a.GK_No=b.gk_no
还是报语法错误,我用是SQL2008 R2
CREATE FUNCTION returntable (@objectname varchar(20))
RETURNS TABLE
AS
RETURN
(
select * from sys.objects where name = @objectname
);
GO
select * from sys.objects cross apply dbo.returntable(name)
我写的例子