-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