如何获取字符串的子串长度 [英] How get length of Sub-string of string
本文介绍了如何获取字符串的子串长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Experts
有些用户在电话栏中插入了数字以外的其他内容。
现在我想删除它们。
有一个查询来查找这类记录:
选择电话
来自人员
其中电话赞 N ' %[أ-ي]%' 和
电话 不 Null
结果:
电话
--------------
داخلي298
داخلي111
مغازه2701646
2802301منزل
如何删除sql查询中的额外信息?
解决方案
尝试以下示例TSQL从任何字符串/ varchar中删除非数字字符。
在sql查询中使用你需要创建函数然后你也可以在任何sql查询中使用。
DECLARE @ cString VARCHAR ( 32 )
DECLARE @ nPos INTEGER
SELECT @ cString = ' 90
%45623 * 6%}〜:@'
SELECT @ nPos = PATINDEX(' %[^ 0-9]%', @ cString )
WHILE @ nPos > 0
BEGIN
SELECT @ cString = STUFF( @ cString , @ nPos , 1 ,' ')
SELECT @ nPos = PATINDEX(' %[^ 0-9]%', @ cString )
END
SELECT @ CSTRING 跨度>
Hello Experts
Some users had inserts something other than numbers in the 'Tel' column.
Now I want to remove them.
There is a query to find these kind of records:
Select Tel
From Person
Where Tel Like N'%[أ-ي]%' And
Tel Is Not Null
Results:
Tel
--------------
داخلي 298
داخلي 111
مغازه 2701646
2802301 منزل
How I can Remove the extra info in a sql query?
解决方案
Hi,
Try below sample TSQL to remove non numeric characters from any string/varchar.
To use in sql query you need to create function and then you can use in any sql query also.
DECLARE @cString VARCHAR(32) DECLARE @nPos INTEGER SELECT @cString = '90
%45623 *6%}~:@' SELECT @nPos = PATINDEX('%[^0-9]%', @cString) WHILE @nPos > 0 BEGIN SELECT @cString = STUFF(@cString, @nPos, 1, '') SELECT @nPos = PATINDEX('%[^0-9]%', @cString) END SELECT @cString
这篇关于如何获取字符串的子串长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文