Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8429749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:25:22+00:00 2026-06-10T05:25:22+00:00

We received an MSSQL database with many tables and fields which we need to

  • 0

We received an MSSQL database with many tables and fields which we need to clean. One of the things we need to do is remove all quotes (chr(34) and chr(39)) from any text fields.

Looking for a way to do this automatically instead of manually.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:25:24+00:00Added an answer on June 10, 2026 at 5:25 am

    A non-set based approach:
    The below sproc basically does what you need.
    It uses nested WHILE loops

    • the parent WHILE loop gets all user defined tables
    • the nested WHILE loop goes through all char-based columns (which you
      can modify). Then it uses dynamic SQL to update with new string.

    For many tables and large sized tables, this would obviously take quite a while to complete. I am sure this can be optimized better.
    If anyone can find a set-based approach, that would be something.

    Source & Courtesy: Vyaskn

    CREATE PROC SearchAndReplace
    (
        @SearchStr nvarchar(100),
        @ReplaceStr nvarchar(100)
    )
    AS
    BEGIN
    
        SET NOCOUNT ON
    
        DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110), @SQL nvarchar(4000), @RCTR int
        SET  @TableName = ''
        SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')
        SET @RCTR = 0
    
        WHILE @TableName IS NOT NULL
        BEGIN
            SET @ColumnName = ''
            SET @TableName = 
            (
                SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
                FROM    INFORMATION_SCHEMA.TABLES
                WHERE       TABLE_TYPE = 'BASE TABLE'
                    AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
                    AND OBJECTPROPERTY(
                            OBJECT_ID(
                                QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
                                 ), 'IsMSShipped'
                                   ) = 0
            )
    
            WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
            BEGIN
                SET @ColumnName =
                (
                    SELECT MIN(QUOTENAME(COLUMN_NAME))
                    FROM    INFORMATION_SCHEMA.COLUMNS
                    WHERE       TABLE_SCHEMA    = PARSENAME(@TableName, 2)
                        AND TABLE_NAME  = PARSENAME(@TableName, 1)
                        AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
                        AND QUOTENAME(COLUMN_NAME) > @ColumnName
                )
    
                IF @ColumnName IS NOT NULL
                BEGIN
                    SET @SQL=   'UPDATE ' + @TableName + 
                            ' SET ' + @ColumnName 
                            + ' =  REPLACE(' + @ColumnName + ', ' 
                            + QUOTENAME(@SearchStr, '''') + ', ' + QUOTENAME(@ReplaceStr, '''') + 
                            ') WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
                    EXEC (@SQL)
                    SET @RCTR = @RCTR + @@ROWCOUNT
                END
            END 
        END
    
        SELECT 'Replaced ' + CAST(@RCTR AS varchar) + ' occurence(s)' AS 'Outcome'
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to add values received from MySQL into an array (PHP). Here is
I received an e-mail which contained a link that looked like it was to
I recently purchased PAF files from the Royal Mail. I've received them all but
I have unpredictable frequency of Incoming csv data file which I need to store
I need to set up a MySQL environment that will support adding many unique
Two applications are using the same MSSQL database. My application is using sqlalchemy with
I'm planning to implement a desktop application which stores all the SMSs and senders'
I am storing sms received from twilio in a database so I can use
how would I format a datetime string received from MySQL? For example, when I
Received a strange error when using secure websockets in Safari with Webbit server. Error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.