检查字符串是否在SQL中包含重音字符? [英] Check If the string contains accented characters in SQL?

查看:106
本文介绍了检查字符串是否在SQL中包含重音字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果输入字符串包含任何重音字符,我想执行一个任务,否则在SQL中执行另一个任务。有什么方法可以在SQL中检查这种情况?

I want to perform a task if the input string contain any accented characters else do another task in SQL. Is there any way to check this condition in SQL ?

例如:

@myString1 = 'àéêöhello!'

IF(@myString1 contains any accented characters)
  Task1
ELSE
  Task2


推荐答案

SQL小提琴: http://sqlfiddle.com/#!6/9eecb7d/1607

declare @a nvarchar(32) = 'àéêöhello!'
declare @b nvarchar(32) = 'aeeohello!'

select case 
    when (cast(@a as varchar(32)) collate SQL_Latin1_General_Cp1251_CS_AS) = @a 
    then 0 
    else 1 
end HasSpecialChars

select case 
    when (cast(@b as varchar(32)) collate SQL_Latin1_General_Cp1251_CS_AS) = @b 
    then 0 
    else 1 
end HasSpecialChars

(基于此处的解决方案:怎么样我可以删除字符串的重音符号吗?

(based on solution here: How can I remove accents on a string?)

这篇关于检查字符串是否在SQL中包含重音字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆