Insert single qoutes into a column for a SQL table

Culbertson Geoffrey 60 Reputation points
2023-08-25T14:48:32.8366667+00:00

This seems simple enough but I am struggling with how to do it. I need add single quotes around all the records in a column call Manager in a table called ChronusExport. I know how to add them in a select statement but not how to do a bulk update to all the records in that table.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,494 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 120.2K Reputation points MVP
    2023-08-25T15:45:51.2266667+00:00

    So use the same SELECT statement, but just add INSERT on top;

    INSERT (col1, col2, col3, ..)
    SELECT ..., quotname(Manager, ''''), ...
    

    Note that quotename will return NULL if the input is more than 128 characters.

    Note also that qoutename will also double any single quotes in the Manager column. So Brian O'Brien will result in 'Brian O''Brien'.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.