MSSQL表值函数在sql语句中的使用问题

select s.billid ,t.billid from s_order s
cross apply (select billid from ReferRelation(12,s.billid )) as t
这个语句会报错,其中ReferRelation是一个表值函数。
但是把表值函数的参数换成常量就没有问题,如下:
select s.billid ,t.billid from s_order s
cross apply (select billid from ReferRelation(12,3 )) as t
请高手指点,谢谢!

sql中使用查询表的字段,要么作为查询结果字段,要么作为条件匹配字段,代表表中的一列,不做为具体值使用,你直接使用s.billid匹配具体值肯定是不对的

s.billid 你需要重新写个sql查出来select billid from ReferRelation(12,select billid from s_order limit 1)