i have string value as "ORA_Sampl_34_20120530_123456.txt" from this string i want to get output as "34" using sql query.
我有字符串值为“ORA_Sampl_34_20120530_123456.txt”从这个字符串我希望使用SQL查询输出为“34”。
1 个解决方案
#1
1
This solution should be good for learning:
这个解决方案应该有助于学习:
DECLARE @text NVARCHAR(50) = 'ORA_Sampl_34_20120530_123456.txt',
@start INT,
@end INT
SELECT @start = CHARINDEX('_', @text, CHARINDEX('_',@text,1)+1)+1
SELECT @end = CHARINDEX('_',@text, @start)
SELECT SUBSTRING(@text, @start, @end - @start)
#1
1
This solution should be good for learning:
这个解决方案应该有助于学习:
DECLARE @text NVARCHAR(50) = 'ORA_Sampl_34_20120530_123456.txt',
@start INT,
@end INT
SELECT @start = CHARINDEX('_', @text, CHARINDEX('_',@text,1)+1)+1
SELECT @end = CHARINDEX('_',@text, @start)
SELECT SUBSTRING(@text, @start, @end - @start)