Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: 2 days ago @ 7:05 PM
Points: 1,922, Visits: 6,420
Edit: I misunderstood your question... What's with the NULLS?

-- Alan Burstein



Best practices for getting help on SQLServerCentral
Need to split a string? Try DelimitedSplit8K or DelimitedSplit8K_LEAD (SQL 2012+)
Need a pattern-based splitter? Try PatternSplitCM
Need to remove or replace those unwanted characters? Try PatExclude8K and PatReplace8K.

"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
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: Friday, June 17, 2016 4:41 AM
Points: 258, Visits: 554
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: Sunday, November 15, 2015 10:02 AM
Points: 196, Visits: 93
Your Question is not clear.
Post #1389501
Posted Wednesday, November 28, 2012 8:32 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Friday, July 22, 2016 3:30 PM
Points: 15,794, Visits: 16,150
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