我的查询使用“存在”函数作为过滤器,并且其中包含标量值函数。标量值函数包含 cte 和“(select top 1 1)”。当我使用存在时,它根本不会过滤。相反,当我使用“where 1 =(svf)”时,它似乎有效。我在存在查询中错过了什么或任何错误吗?
SELECT * FROM TBL1
WHERE EXISTS (SELECT SVF(1,2))
--where SVF is my scalar valued from which returns bit and looks like as shown below.
CREATE FUNCTION SVF
(
@x int,
@y int
)
RETURNS bit
AS
BEGIN
declare @result bit
;WITH T1
AS (
SELECT * from tbl2
)
SELECT @result= (select top 1 1
FROM t1
)
return isnull(@result,0)
END
GO
--the following query works
SELECT * FROM TBL1
WHERE 1=(SELECT SVF(1,2))