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

Function - Spilt Columns into multiple rows Expand / Collapse
Author
Message
Posted Friday, October 19, 2012 6:20 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, October 2, 2014 6:33 PM
Points: 7, Visits: 71

Hi

I have a table which has columns containing sales values for each month for example..

Id, versionId, jul,aug,sep,oct,nov,dec,jan,feb,mar,apr,may,jun

The 'versionId' joins to the period table which has the end dates for each month

versionId, juldate,augdate,sepdate,octdate,novdate,decdate,jandate,febdate,madater,aprdate,maydate,jundate

What i need to do is return individual rows for each month with the corresponding period date..

Id
versionId
salesvalue
salesenddate

I have been looking at Multi-Statement Table-Value Functions but haven't been able to get anywhere near this result..

Any assistance greatly appreciated..


Post #1375068
Posted Saturday, October 20, 2012 5:22 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, May 22, 2013 12:57 AM
Points: 20, Visits: 78
Please provide table structures and the the output you want clearly. Then only someone can suggest something.
Post #1375097
Posted Saturday, October 20, 2012 6:43 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 2:57 AM
Points: 405, Visits: 1,137
sounds like you may need something like a pivot table query


_____________________________________________________________________________
MCITP: Business Intelligence Developer (2005)
Post #1375102
Posted Monday, October 22, 2012 9:31 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 1:04 PM
Points: 13,086, Visits: 12,553
graham 47698 (10/19/2012)

Hi

I have a table which has columns containing sales values for each month for example..

Id, versionId, jul,aug,sep,oct,nov,dec,jan,feb,mar,apr,may,jun

The 'versionId' joins to the period table which has the end dates for each month

versionId, juldate,augdate,sepdate,octdate,novdate,decdate,jandate,febdate,madater,aprdate,maydate,jundate

What i need to do is return individual rows for each month with the corresponding period date..

Id
versionId
salesvalue
salesenddate

I have been looking at Multi-Statement Table-Value Functions but haven't been able to get anywhere near this result..

Any assistance greatly appreciated..




As previously stated this does sound like a PIVOT or a cross tab. If you want some help you need to provide enough information so we can help. Please read the article on best practices found at the first link in my signature.


_______________________________________________________________

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 #1375526
Posted Monday, October 22, 2012 2:42 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, September 19, 2014 5:16 AM
Points: 887, Visits: 1,774
actually sounds more like an unpivot to normalize a data structure.


http://msdn.microsoft.com/en-us/library/ms177410(v=sql.105).aspx at the very bottom is the unpivot


EDIT Forgot url tags



For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden for the best way to ask your question.

For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw

Need to Split some strings? Jeff Moden's DelimitedSplit8K
Jeff Moden's Cross tab and Pivots Part 1
Jeff Moden's Cross tab and Pivots Part 2

Jeremy Oursler
Post #1375732
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse