Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Convert rows to columns Expand / Collapse
Author
Message
Posted Tuesday, November 27, 2012 8:10 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, June 4, 2013 6:44 PM
Points: 46, Visits: 72
We have a following table:
[Day] [Time]
Mon 07:00
Tue 12:00
Mon 10:00
Mon 15:00
Tue 15:00
Tue 20:00
I want to make a query in sql 2005 to have the following result:
07:00 10:00 12:00 15:00 20:00
Mon Mon Tue Mon Tue
NULL NULL NULL Tue NULL

Please help me do it?
Thank you very much!
Post #1389487
Posted Tuesday, November 27, 2012 8:40 PM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Yesterday @ 8:56 PM
Points: 612, Visits: 2,855
Edit: I misunderstood your question... What's with the NULLS?

-- Alan Burstein



Read this article for best practices on asking questions.
Need to split a string? Try this (Jeff Moden)
Need a pattern-based string spitter? Try this (Dwain Camps)

"I can't stress enough the importance of switching from a 'sequential files' mindset to 'set-based' thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code. " -- Itzek Ben-Gan 2001

My blog
Post #1389488
Posted Tuesday, November 27, 2012 9:38 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Sunday, September 14, 2014 12:30 AM
Points: 253, Visits: 540
seems this Cross Tab Procedure will help your to solve this issue



Every rule in a world of bits and bytes, can be bend or eventually be broken
MyBlog About Common dialog control
A Visualizer for viewing SqlCommand object script
Post #1389500
Posted Tuesday, November 27, 2012 9:39 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, February 18, 2013 1:47 AM
Points: 196, Visits: 87
Your Question is not clear.
Post #1389501
Posted Wednesday, November 28, 2012 8:32 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:13 PM
Points: 13,085, Visits: 12,551
goodtomorrow01 (11/27/2012)
We have a following table:
[Day] [Time]
Mon 07:00
Tue 12:00
Mon 10:00
Mon 15:00
Tue 15:00
Tue 20:00
I want to make a query in sql 2005 to have the following result:
07:00 10:00 12:00 15:00 20:00
Mon Mon Tue Mon Tue
NULL NULL NULL Tue NULL

Please help me do it?
Thank you very much!


Nobody can help you because you didn't provide enough details for somebody to help. Please see the first link in my signature for best practices when posting a question.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1389837
Posted Thursday, November 29, 2012 12:31 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, June 4, 2013 6:44 PM
Points: 46, Visits: 72
Thank you very much for interested in my question. However, I find out answer from here : http://social.msdn.microsoft.com/Forums/en/transactsql/thread/07dd8fb0-4c2c-4ed0-a6a6-4ca6a488f2d0
Again, thanks anyway and hope continue getting your help for next time.
Post #1390316
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse