tags:

views:

2585

answers:

1

Hello,

I've found a solution for finding the position of an underscore with PATINDEX :

DECLARE @a VARCHAR(10)  
SET     @a = '37_21'

PRINT PATINDEX('%_%', @a)                    -- return 1 (false)
PRINT PATINDEX('%!%', REPLACE(@a, '_', '!')) -- return 3 (correct)

Have you other ideas ?
Like a way to escape the underscore character ?

Thanks

+4  A: 

I've always done it with brackets: '%[_]%'

Curt Hagenlocher
+1 see: http://msdn.microsoft.com/en-us/library/ms187489(SQL.90).aspx, Section "Searching for Wildcard Characters"
Tomalak