Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Updating a field with apostrophes
Message
From
27/11/2014 14:29:34
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
27/11/2014 13:01:00
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Application:
Desktop
Miscellaneous
Thread ID:
01611499
Message ID:
01611504
Views:
51
>Hi,
>
>I know this should be an easy one, but I'm completely blank.
>
>I have a table with the following value in a column/field:
>
>
exec('insert into AgentBranches ([LocationCode]) values (''CO') select * from AgentBranches where ID = scope_identity()')
>
>Note that there is only one apostrophe after "CO". I need to update this value by adding in the missing apostrophe.
>
>so my code should be:
>
>
UPDATE [cman].[dbo].[dd_tables]
>   SET [insert_command] = exec('insert into AgentBranches ([LocationCode]) values (''CO'') select * from AgentBranches where ID = scope_identity()')
> WHERE table_name = 'AgentBranches'
>
>My problem is, what do I surround the new string with? When I use single quotes I get an error about missing quote.
>
>solved
>
>
UPDATE [cman].[dbo].[dd_tables]
>   SET [insert_command] = replace(cast([insert_command] as varchar(500)), 'CO'')', 'CO'''')')
> WHERE table_name = 'AgentBranches'
Hi Frank

Parameterizing is the easiest way to deal with that.
Previous
Reply
Map
View

Click here to load this message in the networking platform