SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Function - Spilt Columns into multiple rows


Function - Spilt Columns into multiple rows

Author
Message
graham 47698
graham 47698
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 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..
justmohit
justmohit
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 78
Please provide table structures and the the output you want clearly. Then only someone can suggest something.
dave-dj
dave-dj
SSC Eights!
SSC Eights! (980 reputation)SSC Eights! (980 reputation)SSC Eights! (980 reputation)SSC Eights! (980 reputation)SSC Eights! (980 reputation)SSC Eights! (980 reputation)SSC Eights! (980 reputation)SSC Eights! (980 reputation)

Group: General Forum Members
Points: 980 Visits: 1149
sounds like you may need something like a pivot table query

_____________________________________________________________________________
MCITP: Business Intelligence Developer (2005)
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25902 Visits: 17518
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 Modens 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)
CapnHector
CapnHector
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1331 Visits: 1789
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search