home
training courses
why choose us?
solutions
support
company
LearnItFirst User Forum
Welcome Guest
Search
|
New Posts
|
Members
|
Log In
|
Register
SQL Server Forum - LearnItFirst.com
»
SQL Server Database Administration
»
General SQL Database Question & Answer
»
SQL tip
SQL tip
Options
Previous Topic
·
Next Topic
moonsulu
Posted:
Monday, March 15, 2010 10:20:05 AM
Rank: Newbie
Joined: 3/18/2009
Posts: 6
Points: 18
hi guys i have this table. i've tried things but i am not skilled enough to make it to work.
date quantity
1/1/2009 1
2/1/2009 3
5/1/2009 7
9/1/2009 2
1/1/2010 4
2/1/2010 1
3/1/2010 8
and would like to have a recordset to look like this:
year jan feb mar april may jun jul aug sep oct nov dec
2009 1 3 0 0 7 0 0 0 2 0 0 0
2010 4 1 8
thanks for any ideas?
Back to top
Scott Whigham
Posted:
Monday, March 15, 2010 10:29:44 AM
Rank: Super Mod
Joined: 3/20/2006
Posts: 476
Points: 1,053
Where do you live?: Dallas, TX
Yes, this is a "crosstab" or a "pivot table" query. You will need to either use the PIVOT() operator or write individual CASE statements. Too much to explain here but my
SQL Server queries course
has a lot on this exact thing:
http://www.learnitfirst.com/Course/160/Video/2369/Pivot-Tables-and-Cross-Tab-Queries.aspx
http://www.learnitfirst.com/Course/160/Video/2370/Design-Pattern-for-Pivot-Tables-and-Crosstabs.aspx
http://www.learnitfirst.com/Course/160/Video/2408/PIVOT-and-Crosstab-Queries.aspx
http://www.learnitfirst.com/Course/160/Video/2409/Design-Pattern-for-Pivot-Tables-and-Crosstabs-Two.aspx
Back to top
moonsulu
Posted:
Monday, March 15, 2010 11:15:18 AM
Rank: Newbie
Joined: 3/18/2009
Posts: 6
Points: 18
hi Scott Whigham, thanks very much, i will look into those. have a nice day!
Back to top
Users browsing this topic
Guest
Forum Jump
SQL Server Database Administration
- General SQL Database Question & Answer
- Backup, Recovery and Disaster Recovery
- SQL Server Security
- Integration Services (SSIS) and DTS
Transact-SQL Programming
- DML (SELECT, INSERT, UPDATE, DELETE) Questions
- Stored Procedures, Triggers, & Functions
SQL Server Scripts, Code Samples and SSMS Custom Reports
- All SQL Server Versions
- SQL Server 2005/2008
- SQL Server Management Studio Custom Reports
Customer Service
- Video Requests
You
cannot
post new topics in this forum.
You
cannot
reply to topics in this forum.
You
cannot
delete your posts in this forum.
You
cannot
edit your posts in this forum.
You
cannot
create polls in this forum.
You
cannot
vote in polls in this forum.
SQL Server 2005 DBA Training Videos
SQL Server 2008 DBA Training Videos
Email this topic
RSS Feed
Watch this topic
Print this topic
Normal
Threaded