SQL Replace comma in results without using replace

sql, sql-server

Solution

I believe you may be confused as to what the REPLACE function is doing. You can use REPLACE within your SELECT statement without altering the data in the database:

SELECT REPLACE(MyField, ',', ';') AS NewFieldName
FROM MyTable

Problem

I feel like this should be simple enough to do, but have not found any solutions that didn't use replace so far. I have the following select statement I am running, and for some of the columns there are commas separating the values. I would like to replace these commas with semicolons, however I only want to do it in the select statement. I don't want it to alter the values in the tables at all. This is not a one off statement either, or I'd just replace all the commas with semicolons and then revert back. ``` SELECT a.Category_Id, a.Category_Name, ISNULL(b.Category_Alias, '') as Category_Alias, ISNULL(b.SUPPORT_NAMES, '') as SUPPORT_NAMES FROM Categories a INNER JOIN CategoryInfo b on b.Category_Id=a.Category_Id ``` For the Category_Alias column, the records are actually stored like `CS, Customer Support` and I want that to show up as `CS; Customer Support` just for the select statement.

Original source