How to display all the columns in one single column

Who is online?  0 guests and 0 members
Home  »  Forums   »  microsoft business intelligence   »  sql server   » How to display all the columns in one single column

How to display all the columns in one single column

Topic RSS Feed

Posts under the topic: How to display all the columns in one single column

Posted: 12/7/2011

Jedi Youngling 74  points  Jedi Youngling
  • Joined on: 11/28/2011
  • Posts: 27

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


Posted: 12/7/2011

Jedi Youngling 74  points  Jedi Youngling
  • Joined on: 11/28/2011
  • Posts: 27

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.


Posted: 12/7/2011

Jedi Youngling 74  points  Jedi Youngling
  • Joined on: 11/28/2011
  • Posts: 27

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.

Thanks


Posted: 12/7/2011

Padawan 1392  points  Padawan
  • Joined on: 1/3/2010
  • Posts: 250

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.


Posted: 12/7/2011

Jedi Youngling 74  points  Jedi Youngling
  • Joined on: 11/28/2011
  • Posts: 27
Answered  Answered

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

 



Page 1 of 1 (5 items)