Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use table-valued function in SQL Server where clause

I have a table-valued function and it returns a set of id data. I want to put the function in my query;

SELECT * 
FROM caritbl 
WHERE cari_id IN (dbo.fn_AtamaliCariListe(37))

Any suggestions?

Edit: I am using SQL Server

like image 842
aykut aydoğan Avatar asked Dec 20 '22 01:12

aykut aydoğan


1 Answers

In this case you can use this function like a table. Normally you perform your query writing like;

select * from XTable x where x.col in (select y.col from YTable y)

when you use Table-valued functions also you can do it in the same way;

select * from XTable x where x.col in (select y.col from dbo.fn_YourFunction(idparameter) y)

Not that your table-valued function ought to return a result with a column named "col"

like image 123
sulhadin Avatar answered Dec 29 '22 00:12

sulhadin