Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Updating a field with apostrophes
Message
De
27/11/2014 14:29:34
Mike Yearwood
Toronto, Ontario, Canada
 
 
À
27/11/2014 13:01:00
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Application:
Desktop
Divers
Thread ID:
01611499
Message ID:
01611504
Vues:
50
>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.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform