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.
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):