Posted: 12/7/2011
Hello All,
I have a requirement like this. In sql I need to get the result set like
Name|Address|Phone
Tom|333 red oak Dr|666666
sam|624 St Mictchel ln|768888
All this should come in one single column in the result set. I got the data seperated with pipe in one single column. How can I get the header as Name|Address|Phone. I have tried like this as alias 'Name|Address|Phone' But no luck.
Any help is much appreciated.
Thanks
That worked. But I am having total 15 columns. It is allowing only till 13 columns. When I include last 2 columns it is throwing an error as 'The identifier is too long.The maximum size is 128.' Please help how to include the last 2 column headers.
I need to get all the column names in the first row like name|address|phone and then the data. All this should be in one single column. How to do this in SQL.
You need to clarify your request. Do you need to convert multiple columns into one column, or you want to split 1 column into multiple columns based on comma?
In order you to have column names, you might want to use sys.columns and concatenate them. Is that what you want?
Try to give 1 example with data source table and the output you need, so we can understand.
I am sorry for not being clear. originally my code generates 15 columns. But I want to modify my code to get the result set as all those 15 columns in one single column seperated with pipe(|). I just got the result the way I want.
I was looking for
Name|Address|Phone----1st row
tom|234 dr|44555
sam|345 dr|67586
I was asking about how to get the column headers as the first row. I just appended this to my original query.
SELECT 'Name|Address|Phone'
UNION ALL
Select .........
This solved my issue.
Thanks for the reply