By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,806 Members | 1,829 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,806 IT Pros & Developers. It's quick & easy.

trick for displaying result? SQL Server 2005

P: 5
I run many queries per day. The results are usually 1 row with many, many columns. Is there a trick/free tool to display this row as 1 column instead?

example:

col 1 col 2 col 3 col 4 ....
data1 data2 data2 data4....

to

col1: data1
col2: data2
col3: data3
col4: data4

for adhock queries.

Thanks

~Gina_M~
Nov 5 '09 #1
Share this Question
Share on Google+
3 Replies


Delerna
Expert 100+
P: 1,134
How many columns?

You could try
Expand|Select|Wrap|Line Numbers
  1. select 'Col1' as [Field],col1 as Data from .....
  2. union all
  3. select 'Col2' as [Field],col2 as Data from .....
  4. union all
  5. select 'Col3' as [Field],col3 as Data from .....
  6. ........
  7. etc
  8. ........
  9.  

May I ask, if you want the data to display that way, why the table wasn't designed that way
Nov 5 '09 #2

nbiswas
100+
P: 149
Give a shot with PIVOT if you are using Sql Server 2005+ else for downward version look into this tutorialhttp://jdixon.dotnetdevelopersjourna...0_and_2005.htm
Nov 8 '09 #3

P: 5
Thanks much for the responses.

I will give the pivot a try. The union example probably works as well but I was looking for something more generic.

Also, maybe using FOR XML might give me something easily readable.

SELECT top 1 *
FROM orders
FOR XML RAW('orders'), ELEMENTS

works pretty good. I was just trying to get something in a readable format to quickly send in an email or such.

Gina_M
Nov 16 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.