April 7, 2005 at 2:01 am
Hi
I'm using a cursor to read values into a char variable, then edit it and place it back into the table. However, if the string is something like Earl's Diner, it doesn't re-insert the row. The offending character needs to be changed from ' to '', but I cannot seem to achieve this with the replace function. Is there a way for me to search through the string and replace ' with '' before trying to add it to the table?
Thanks
B
April 7, 2005 at 2:23 am
It would be helpful, if you can provide the code, along with sample data and desired output.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
April 7, 2005 at 2:30 am
try this
select replace('tester''s', '''','''''')
>tester''s
>(1 row(s) affected)
you need to double (escape) the single quotes so SQL Server can parse them
cheers
dbgeezer
April 7, 2005 at 10:16 am
have you tried replacing using ascii ?! 34 for 39 or some such ?!
**ASCII stupid question, get a stupid ANSI !!!**
April 11, 2005 at 6:29 am
Hi
Thank you very much for your help. I have added the replace function in the select that forms part of my cursor
declare cr_test cursor for
select replace(location,char(39),char(34)) from test_table
open cr_test
fetch next from cr_test into @location
while @@fetch_status = 0
begin
print @location
fetch next from cr_test into @location
end
close cr_test
deallocate cr_test
and it works PERFECTLY with my dynamic sql statements!
Thanks again!
Brenchia
April 11, 2005 at 6:29 am
Hi
Thank you very much for your help. I have added the replace function in the select that forms part of my cursor
declare cr_test cursor for
select replace(location,char(39),char(34)) from test_table
open cr_test
fetch next from cr_test into @location
while @@fetch_status = 0
begin
print @location
fetch next from cr_test into @location
end
close cr_test
deallocate cr_test
and it works PERFECTLY with my dynamic sql statements!
Thanks again!
Brenchia
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy