2016-02-12 37 views

回答

1
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 
+0

@tharun只是檢查可能對你有用 – mohan111

+0

這工作得很好,當u有幾行,但我已經有這個字段的表,和高達500萬records.-數據計數可以請你幫我帶數據當它巨大時。 –

+0

即使有多少條記錄,它也可以很好地選擇數字字符。但即將到來的表現肯定會帶來收費,這完全取決於你的環境,表格設計和編碼標準@tharunthamaiah – mohan111