-3
我試圖從SQL Server中的字符串中取出SO#而不使用UDF。例如:SQL Server 2012:從字符串中提取SO#
this is the SO#12345 55
this is the SO12345 55
this is the SO 12345 55
this is the SO#12345/55
無論特殊字符和空格如何,我只想抓取12345。
我試圖從SQL Server中的字符串中取出SO#而不使用UDF。例如:SQL Server 2012:從字符串中提取SO#
this is the SO#12345 55
this is the SO12345 55
this is the SO 12345 55
this is the SO#12345/55
無論特殊字符和空格如何,我只想抓取12345。
DECLARE @Table1 TABLE
(VAL varchar(23))
;
INSERT INTO @Table1
(VAL)
VALUES
('this is the SO#12345 55'),
('this is the SO12345 55'),
('this is the SO 12345 55'),
('this is the SO#12345/55')
;
SELECT LEFT(subsrt, PATINDEX('%[^0-9]%', subsrt + 't') - 1)
FROM (
SELECT subsrt = SUBSTRING(val, pos, LEN(val))
FROM (
SELECT val, pos = PATINDEX('%[0-9]%', val)
FROM @Table1
) d
) t
@tharun只是檢查可能對你有用 – mohan111
這工作得很好,當u有幾行,但我已經有這個字段的表,和高達500萬records.-數據計數可以請你幫我帶數據當它巨大時。 –
即使有多少條記錄,它也可以很好地選擇數字字符。但即將到來的表現肯定會帶來收費,這完全取決於你的環境,表格設計和編碼標準@tharunthamaiah – mohan111