Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Updating a field with apostrophes
Message
De
27/11/2014 13:01:00
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Updating a field with apostrophes
Versions des environnements
SQL Server:
SQL Server 2005
Application:
Desktop
Divers
Thread ID:
01611499
Message ID:
01611499
Vues:
47
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'
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform