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 2005 Forums
 Transact-SQL (2005)
 Using REPLACE to replace single quotes

Author  Topic 

cagdasal
Starting Member

2 Posts

Posted - 2008-11-17 : 11:24:26
Hello there, i am currently passing in a parameter to a stored procedure which could look something like this for example:
''a'',''b'',''b''

What i would like to do is remove the '' and place it with a single ' so i can use this string in a query quch as:
WHERE xxxx in (@param)

However if i do this:
(REPLACE(@clients, '''','''))
It obviously does not work since it is recognising each ' as an opening quotation

The reason for the duplicate single quotes is just the way the software i am using is passing them in.

Any ideas on how to get around this?

Any help would be greatly appreciated.

p.s. i am using SQL server 2005

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-17 : 11:32:41
cant you just use?

WHERE  ','+REPLACE(@clients, '''''','')+',' LIKE '%,'+ xxxx + ',%' 
Go to Top of Page

cagdasal
Starting Member

2 Posts

Posted - 2008-11-17 : 12:29:44
I dont really know how that would work, basically i want to convert:
''a'',''b'',''c'' into 'a','b','c'

Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-17 : 12:34:54
quote:
Originally posted by cagdasal

I dont really know how that would work, basically i want to convert:
''a'',''b'',''c'' into 'a','b','c'

Thanks


Try it and see
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-17 : 13:23:27
REPLACE(@Clients, CHAR(34), CHAR(39))



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-18 : 04:16:54
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -