即使我在外部查询中使用数值,我也面临错误。
IF OBJECT_ID('tempdb..#TestNumeric') IS NOT NULL
BEGIN
DROP TABLE #TestNumeric
END
CREATE TABLE #TestNumeric (ids INT, Valu NVARCHAR(50))
INSERT INTO #TestNumeric
SELECT 1, '12345' UNION ALL
SELECT 1, '234234 23423' UNION ALL
SELECT 1, '234234'
;WITH CTE
AS
(
SELECT ids, Valu
, Convert(NUMERIC(18,0),Valu) as OriginalNumValue
, ISNUMERIC(Convert(NUMERIC(18,0), Valu) ) IsNumericTrue
FROM #TestNumeric
WHERE ISNUMERIC(Valu) = 1
AND Valu not like '%[^0-9]%'
)
SELECT *
FROM CTE
WHERE Valu = 100
DROP TABLE #TestNumeric
如果我只是删除 WHERE 条件,那么它只显示数值。即使它给出错误并显示读取的其他行。
为什么它读取外部查询中的其他行,因为我已经过滤了?