views:

42

answers:

3

Hello,

Using Microsoft SQL Server 2005 - wondering how can I escape parenthesis in my query?

I'm trying to find the string position of "(" in one of my columns returned, but Management Studio keeps thinking I'm opening another command when I use that. I've tried \ but that isn't escaping it.

Thank you!

+3  A: 

this doesn't work for you?

select charindex('(', yourColumn)
from yourTable
Mladen Prajdic
It appears it does - I had another issue and the Management Studio wasn't showing corresponding closing parenthesis correct. When I use that, my next parenthesis doesn't show as closing out that function, but highlights the actual parenthesis I'm trying to find index on. Thank you.
@evanmortland: can you check the syntax once
Sachin Shanbhag
+1  A: 

You don't need to escape it, see example below:

select charindex('(', x)
from (
    select 'asdasda(adsadas' as x
) a

Output:

8

RedFilter
+1  A: 
select charindex('(',<columnname>) from <tableName>
Sachin Shanbhag