Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
Function - Spilt Columns into multiple rows
Function - Spilt Columns into multiple rows
Rate Topic
Display Mode
Topic Options
Author
Message
graham 47698
graham 47698
Posted Friday, October 19, 2012 6:20 PM
Forum Newbie
Group: General Forum Members
Last Login: Friday, January 25, 2013 7:26 PM
Points: 5,
Visits: 58
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
justmohit
justmohit
Posted Saturday, October 20, 2012 5:22 AM
Grasshopper
Group: General Forum Members
Last Login: 2 days ago @ 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
dave-dj
dave-dj
Posted Saturday, October 20, 2012 6:43 AM
Old Hand
Group: General Forum Members
Last Login: Monday, May 20, 2013 11:47 AM
Points: 380,
Visits: 1,014
sounds like you may need something like a pivot table query
_____________________________________________________________________________
MCITP: Business Intelligence Developer (2005)
Post #1375102
Sean Lange
Sean Lange
Posted Monday, October 22, 2012 9:31 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 1:17 PM
Points: 8,641,
Visits: 8,273
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
Post #1375526
CapnHector
CapnHector
Posted Monday, October 22, 2012 2:42 PM
SSC Eights!
Group: General Forum Members
Last Login: Friday, May 17, 2013 10:07 AM
Points: 935,
Visits: 1,709
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 »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.