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
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
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"
Aykut's answer is the best answer under most circumstances. This is to note that the equivalent join is more complicated than the in. It would be:
SELECT DISTINCT c.*
FROM caritbl c JOIN
dbo.fn_AtamaliCariListe(37) as acl(id)
ON c.cari_id = acl.id;
Note the DISTINCT. Unless we know that the function returns unique values, we need it.
Now, there may be cases where the JOIN is actually better. If the function is non-deterministic, it is possible that SQL Server will re-evaluate it repeatedly for each row processed by the IN. I don't know if SQL Server would do this, but it is possible. A JOIN does guarantee that the function only gets evaluated once.