sql - CROSS APPLY WITH UDF -
create function getbyid ( @id int ) returns table return( select * products productid=@id+10)
function above retruns records of products product id grater 10 .
when used cross apply below
select o.* [order details] o cross apply getbyid(o.productid) p
i in result productid less 10 not possible .
the example uses nortwind database sample available everywhere .
order details table , prodcuts tables linked productid
select* getbyid (1) gives result below
when udf called (as above) result shows productid < 10
can see error ?
if want function return products productid greater 10, should add check clause. example:
create function getbyid ( @id int ) returns table return( select * products productid=@id , productid > 10)
Comments
Post a Comment