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 8083613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:31:42+00:00 2026-06-05T17:31:42+00:00

I will warn you up front, this question borders on silly, but I’m asking

  • 0

I will warn you up front, this question borders on silly, but I’m asking anyway.

The impetus for my question is creating a csv from a query result and some of the fields containing commas already. Obviously, the csv doesn’t know any better and just merrily jacks up my good mood by having some stragglers in non-field columns.

I know I can write

Replace(FieldName, OldChar, NewChar)

for each field, but I’m more curious than anything if there’s a shortcut to replace them all in the query output.

Basically what I’m looking for (logically) is:

Replace(AllFields, OldChar, NewChar)

I don’t know all of the SQL tricks (or many of them), so I thought maybe the SO community may be able to enlighten me…or call me nuts.

  • 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-05T17:31:44+00:00Added an answer on June 5, 2026 at 5:31 pm

    There is no SQL syntax to do what you describe, but as you’ve seen there are many ways to do this with dynamic SQL. Here’s the way I prefer (this assumes you want to replace commas with pipe, change this as you see fit):

    DECLARE @table   NVARCHAR(511),
            @newchar NCHAR(1),
            @sql     NVARCHAR(MAX);
    
    SELECT @table    = N'dbo.table_name',
           @newchar  = N'|', -- tailor accordingly
           @sql      = N'';
    
    SELECT @sql = @sql + ',
      ' + QUOTENAME(name) 
        + ' = REPLACE(CONVERT(NVARCHAR(MAX), ' + QUOTENAME(name) + '),'','',''' 
        + @newchar + ''')'
      FROM sys.columns
      WHERE [object_id] = OBJECT_ID(@table)
      ORDER BY column_id;
    
    SELECT @sql = N'SELECT ' + STUFF(@sql, 1, 1, '')  + ' 
     FROM ' + @table;
    
    PRINT @sql;
    -- EXEC sp_executesql @sql;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I must warn you, this code will hurt your eyes, so please don't judge
First, I will warn you, I am new at this so please bear with
If I don't return anything in a function which returns something, compiler will warn
I noticed today that delete will not work in chrome when this popup blocker
If the user refreshes the page in question it will add another record to
I'm using this jquery code to detect unsaved changes and warn users before they
Basically I am trying to put a button in my app which will warn
The eclipse and checkstyle guys of you will surely now this problem: After organizing
I'm working on a mobile app that will get data from GAE, and I'm
i have this simple rule: .PHONY: test test: src/*Test.php $(PHPUNIT) $?;\ it will look

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.