GPAdiga
GPAdiga

Reputation: 9

how to concatenate Sql query result With some strings?

Have to concatenate sql query result With some strings. I am getting sql query result like this

+--------------------+
|    Some Value      |
+--------------------+
|abc,xyz,amar,akbar  |
+--------------------+
|   hjk,fed,fas      |
|                    |
+--------------------+

I want to concatenate ' with each row result like this and I am using Sql server 2012.

+--------------------------+
|    Some Value            |
+--------------------------+
|'abc','xyz','amar','akbar'|
+--------------------------+
|   'hjk','fed','fas'      |
|                          |
+--------------------------+

Please help me..

Upvotes: 1

Views: 194

Answers (1)

Felix Pamittan
Felix Pamittan

Reputation: 31879

You can add a ' on the start and end of your string. Then REPLACE , with ',':

SQL Fiddle

SELECT '''' + REPLACE(some_value, ',', ''',''') + '''' FROM tbl

Upvotes: 1

Related Questions