Skip to content
Advertisement

How to get custom separators in SQL Server query

I have a table in SQL Server that looks like this

Value   First  Last   Email        Phone
-----------------------------------------------------
1       Smith CLEO some@yahoo.com 123456774

If this table was in Oracle and I wanted to get all the properties separated by different separators then I would write something like this

Select 
Value ||','||
First ||'!'||
Last ||'?'||
Email ||'~'||
Phone
from user_table;

I would get output like this

1,Smith!CLEO?some@yahoo.com~123456774

Notice all the separators are different. How can I write a similar select statement for SQL Server?

Advertisement

Answer

You can use concat():

Select concat(Value, ',', First , '!', Last, '?', Email, '~', Phone)
from user_table;
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement