您可以使用LIKE
这样的字符串%ar[e,è,é,Ě]na%
,它将覆盖您的所有工会。如果规则太多,这里有一个函数可以做到这一点:
干得好
CREATE FUNCTION transform (@inStr varchar(300))
returns varchar(255)
AS
BEGIN
DECLARE @registry varchar(300),
@curChar varchar(20),
@outStr varchar(300),
@counter int,
@start int,
@end int;
SET @outStr = '%';
/* Creating a registry of replacements in format {X}[x,X,Xx];
Where {X} contains the character to be replaced,
[x,X,Xx]; contains the replacemet characters
*/
SET @registry = '{e}[e,è,é,Ě];
{s}[ ..other translations of "s" go here.. ];
{n}[n,N];';
set @counter = 1;
WHILE (LEN(@inStr) >= @counter)
BEGIN
SELECT @curChar = substring(@inStr, @counter, 1)
IF (CHARINDEX( '{' + @curChar + '}', @registry, 1) > 0)
BEGIN
SELECT @start = CHARINDEX( '{' + @curChar + '}', @registry, 1) + 2;
SELECT @end = CHARINDEX( ';', @registry, @start);
SELECT @curChar = substring(@registry, @start + 1, @end - @start - 1);
END
SET @outStr = @outStr + @curChar
SET @counter = @counter + 1;
END
SET @outStr = @outStr + '%'
RETURN @outStr;
END
例如这里
... WHERE x.str like transform('arena')
该函数将返回%ar[e,è,é,Ě][n,N]a%
。此字符串表示 - 任何包含以 开头的字符串的值ar
,下一个字符是任何一个e,è,é,Ě
,下一个字符是任何一个n,N
并以 结尾a
。
所以...
select * from myTable where my_name like transform(@token)
将涵盖任何变化,您将不再需要这些工会。