SQL Server 2008 查询查找列中包含非字母数字字符的行
事实上,几周前我自己也被问过这个问题,虽然我确切地知道如何使用 SP 或 UDF 来做到这一点,但我想知道是否有一种快速而简单的方法可以在没有这些方法的情况下做到这一点。我假设有,但我找不到它。
我需要指出的一点是,尽管我们知道允许使用哪些字符(az、AZ、0-9),但我们不想指定不允许使用哪些字符(#@!$ 等)。 .)。另外,我们希望提取有非法字符的行,以便可以将其列出给用户进行修复(因为我们无法控制输入过程,所以此时我们无法执行任何操作) )。
我之前浏览过 SO 和 Google,但找不到任何可以满足我要求的东西。我见过很多例子,它们可以告诉你它是否包含字母数字字符,或者不包含字母数字字符,但是我在查询形式中没有找到能够在句子中拉出撇号的东西。
另请注意,此 varchar
列中的值可以为 null
或 ''
(空)。
I was actually asked this myself a few weeks ago, whereas I know exactly how to do this with a SP or UDF but I was wondering if there was a quick and easy way of doing this without these methods. I'm assuming that there is and I just can't find it.
A point I need to make is that although we know what characters are allowed (a-z, A-Z, 0-9) we don't want to specify what is not allowed (#@!$ etc...). Also, we want to pull the rows which have the illegal characters so that it can be listed to the user to fix (as we have no control over the input process we can't do anything at that point).
I have looked through SO and Google previously, but was unable to find anything that did what I wanted. I have seen many examples which can tell you if it contains alphanumeric characters, or doesn't, but something that is able to pull out an apostrophe in a sentence I have not found in query form.
Please note also that values can be null
or ''
(empty) in this varchar
column.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这还不行吗?
设置
结果
Won't this do it?
Setup
Results
Sql 服务器的正则表达式支持非常有限。您可以将 PATINDEX 与类似的内容一起使用
看看 PATINDEX (Transact-SQL) < /a>
和搜索条件中的模式匹配
Sql server has very limited Regex support. You can use PATINDEX with something like this
Have a look at PATINDEX (Transact-SQL)
and Pattern Matching in Search Conditions
我发现 这个页面有一个相当简洁的解决方案。它的伟大之处在于你可以了解角色是什么以及它在哪里。然后它提供了一种超级简单的方法来修复它(可以将其组合并构建到一段驱动程序代码中以扩展其应用程序)。
然后……
感谢艾曼·安萨里。
I found this page with quite a neat solution. What makes it great is that you get an indication of what the character is and where it is. Then it gives a super simple way to fix it (which can be combined and built into a piece of driver code to scale up it's application).
and then...
Credit to Ayman El-Ghazali.
当我试图在字符串中查找任何特殊字符时,这对我来说最有效
This works best for me when I'm trying to find any special characters in a string