使用SQL Server 2005
我想过滤列值不等于数字
的列表1
Status
010203
Absent
231415
Ramesh
Suresh
...,
我想只从状态栏中获取名称,如
尝试查询
Select Status from table1 where status <> 'absent' and status <> numecivalue
如何提及状态&lt;&gt; numericvalue
预期产出
Table
Status
Ramesh
Suresh
...,
需要查询帮助。
答案 0 :(得分:5)
答案 1 :(得分:2)
使用:
SELECT t.status
FROM table1 t
WHERE t.status != 'absent'
AND ISNUMERIC(t.status) != 1
参考:ISNUMERIC
答案 2 :(得分:0)
SELECT
status
FROM
table1
WHERE
status <> 'absent' AND
ISNUMERIC(status) <> 1
答案 3 :(得分:0)
看看这个weblos ..............
CREATE FUNCTION dbo.IsNumericEx( @value nvarchar(max) )
RETURNS BIT
AS
BEGIN
DECLARE @isInt BIT
SELECT @isInt = 1
WHERE @value NOT LIKE '%[^0-9.-]%'
AND LEN(REPLACE(@value, '.', '')) >= LEN(@value) - 1
AND CHARINDEX('-', @value) IN (0, 1)
AND CHARINDEX('-', @value, 2) = 0
RETURN ISNULL(@isInt, 0)
END
GO
DECLARE @t1 TABLE (title varchar(20))
INSERT INTO @t1
SELECT '123d456' UNION ALL
SELECT '12 3456' UNION ALL
SELECT '123456' UNION ALL
SELECT '1234-56' UNION ALL
SELECT '123456-' UNION ALL
SELECT '-123456' UNION ALL
SELECT '-123-456' UNION ALL
SELECT 'dddfaf56' UNION ALL
SELECT '5532.673' UNION ALL
SELECT '5532673.' UNION ALL
SELECT '.5532.673'
SELECT *
FROM @t1
WHERE dbo.IsNumericEx(title) = 0
SELECT *
FROM @t1
WHERE dbo.IsNumericEx(title) = 1
GO
DROP FUNCTION dbo.IsNumericEx
答案 4 :(得分:0)
您可以在查询中使用RegEx。