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 

enter image description here

when udf called (as above) result shows productid < 10

enter image description here

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

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -