日期:2014-05-18 浏览次数:20490 次
ALTER FUNCTION [dbo].[GET_NUMBER2](@S VARCHAR(100)) RETURNS VARCHAR(100) AS BEGIN WHILE PATINDEX('%[吖-座]%',@S) > 0 BEGIN set @s=stuff(@s,patindex('%[吖-座]%',@s),1,'') END RETURN @S END
------解决方案--------------------
select *,dbo.GET_NUMBER2([列名]) from tb --列名不能加引号
------解决方案--------------------
你这个提取数字的吗?
------解决方案--------------------
IF EXISTS (SELECT 1 FROM SYSOBJECTS WHERE name = 'tba') BEGIN DROP TABLE tba END GO CREATE TABLE tba ( col1 VARCHAR(100) ) GO INSERT INTO tba SELECT '3445wersrede23sde' UNION SELECT '937846rdjkdie37334' GO IF EXISTS (SELECT 1 FROM SYSOBJECTS WHERE name = 'GET_NUMBER2') BEGIN DROP FUNCTION GET_NUMBER2 END GO CREATE FUNCTION GET_NUMBER2(@S VARCHAR(100)) RETURNS VARCHAR(100) AS BEGIN WHILE PATINDEX('%[^0-9]%',@S) > 0 BEGIN set @s=stuff(@s,patindex('%[^0-9]%',@s),1,'') END RETURN @S END GO SELECT dbo.GET_NUMBER2(col1) AS col1 FROM tba col1 344523 93784637334