Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to get to the 2nd ' in a text string

Author  Topic 

Hommer
Aged Yak Warrior

808 Posts

Posted - 2005-04-05 : 11:47:44
I need your help on using charindex or patindex or whatever functions to get the position of 2nd ' in a text string.
The text string (column name where_clause) may looks like this:
"head_order_nbr in ('q120120','q120210')"

CHARINDEX('''',where_clause) will give me the position of first '.
And because the data could also look next, so I cannot use (, =, or ,
head_order_nbr in ('q120210')
head_order_nbr='Q260396'

I know it is a very bad db design,but I have to live with it.

Thanks!

rfrancisco
Yak Posting Veteran

95 Posts

Posted - 2005-04-05 : 12:06:48
Try this:

CHARINDEX('''', where_clause, CHARINDEX('''', where_clause) + 1)

Have you ever considered dynamic SQL to perform your task?
Go to Top of Page

Hommer
Aged Yak Warrior

808 Posts

Posted - 2005-04-05 : 12:21:02
Thanks. It worked!
I totally forgot there is a starting position in charindex.

No, we have not try dynamic sql.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-04-05 : 12:58:35
see:

http://www.sqlteam.com/item.asp?ItemID=11499

For help on working with lists of values and parsing them using a CSV. Don't use dynamic SQL if you can avoid it.

- Jeff
Go to Top of Page
   

- Advertisement -