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.
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.
UPDATE [cman].[dbo].[dd_tables] SET [insert_command] = replace(cast([insert_command] as varchar(500)), 'CO'')', 'CO'''')') WHERE table_name = 'AgentBranches'