检索数字和特殊字符 [英] retrieving numeric number and special character
本文介绍了检索数字和特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我已经记录了"20112312438_AjaxURLS.txt_123546675",在其中仅需要在网格视图中显示"AjaxURLS.txt".将替换所有数字和特殊字符的查询是什么?请帮助
Hi all,
I have record "20112312438_AjaxURLS.txt_123546675" where I need to display in grid view only "AjaxURLS.txt" .What will be the query for that to replace all number and special character ? please help
推荐答案
使用Substring函数来跟踪"_"字符.
在此处查看其详细用法:
http://msdn.microsoft.com/en-us/library/ms187748.aspx [ ^ ]
Use Substring function to track the ''_'' character.
See its detailed use here:
http://msdn.microsoft.com/en-us/library/ms187748.aspx[^]
select charindex(''_'',[Fieldname])将为下划线给出一个整数
选择substring([Fieldname],start,length)将减少字符串
根据需要使用组合来减少您的字段.为此,您将需要嵌套查询.
select charindex(''_'',[Fieldname]) will give an integer for the underscore
select substring([Fieldname],start,length) will reduce the string
use a combination to reduce your field as required. You will need nested queries to do this.
从给出的 ^ ]
检查是否对您有帮助
Slightly modified from the answer given here[^]
Check if it may help you
DECLARE @InputString NVARCHAR(MAX)
DECLARE @Delimiter NVARCHAR(40)
DECLARE @Pos INT
DECLARE @NextString NVARCHAR(40)
SET @InputString = '20112312438_AjaxURLS.txt_123546675'
SET @Delimiter = 1
SET @Pos = 1
SET @InputString = @InputString + @Delimiter
CREATE TABLE #Results(Tokens NVARCHAR(MAX))
WHILE (@pos<>0)
BEGIN
SET @NextString = replace(@inputstring,@delimiter,'')
set @delimiter=@delimiter+1
INSERT INTO #Results VALUES (@NextString)
update #results set tokens=@nextstring
SET @InputString = replace(@NextString,'_','')
SET @pos = charindex(@Delimiter,@InputString)
END
SELECT distinct replace(tokens,'0','') FROM #Results
DROP TABLE #Results
这篇关于检索数字和特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文