Skip to content
Advertisement

How to add ” and , for multiple ID in SQL Server

I am writing a SELECT query that has multiple id, and I have to manually add '','' (e.g '12L','22C').

I have around 2000 id in an Excel sheet.

Is there any quicker way to add ”,” to all the ID?

Advertisement

Answer

Here is a conceptual example for you. It will work in SQL Server 2012 onwards.

It is a three step process:

  1. Convert input string into XML.
  2. Convert XML into a relational resultset inside the CTE.
  3. Join with a DB table.

SQL

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement