轉自:http://www.maomao365.com/?p=6410
摘要:
下文主要分享從指定字串或列中獲取數字資訊,如下所示:
實驗環境:sql server 2000
----編寫sql函式 create function getShuZi(@tmp nvarchar(800)) returns nvarchar(800) as begin while PATINDEX(`%[^0-9]%`, @tmp) > 0 begin set @tmp = STUFF(@tmp, PATINDEX(`%[^0-9]%`, @tmp), 1, ``); end; return @tmp; end go ----測試sql函式 SELECT dbo.getShuZi(`貓貓小屋maomao365.com-sql教程專用網站`) go drop function dbo.getShuZi go