DECLARE
@TableWithBadRows
TABLE
(
Id
INT
identity(1, 1)
PRIMARY
KEY
,description
VARCHAR
max
)
);
INSERT
INTO
@TableWithBadRows (description)
VALUES
'test1'
), (
'I am OK'
'Filter me, please.'
SELECT
*
FROM
WHERE
description
LIKE
'%[^a-z0-9]%'
;
,(
'Let them be & be happy'
CHAR
(200))
(137))
(10) +
(13) +
'Test more'
@TableWithBadRows;
'%[^A-Z0-9%]%'
@i
= 32;
@pattern
) =
'^a-Z0-9'
,@ch
(1);
WHILE @i < 47
BEGIN
SET
@ch =
(@i)
IF @ch =
'_'
@pattern = @pattern +
'['
+ @ch +
']'
ELSE
@pattern = @pattern + @ch + @ch;
@pattern = @pattern + @ch;
@i = @i + 1;
END
@i = 58;
WHILE @i < 65
'%['
+ @pattern +
']%'
'%[^A-Za-z0-9% ]%'
COLLATE
Latin1_General_BIN;
This article participates in the TechNet Guru for August competition.
Naomi N edited Original. Comment: Forgot to add my own tag!
Naomi N edited Revision 2. Comment: 2 more links in See Also to my blogs in BeyondRelational
Naomi N edited Revision 7. Comment: Formatting
Yes, I found that we may need to use binary collation or any other particular collation if we want to properly filter non English characters. I may need to explore this problem a bit more.
It's great solution!
Its not bad to add that this solution just work for English characters and numbers. Non-English characters needs to customize the code.