Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 CrossTab ??

Author  Topic 

Rheinhardt
Yak Posting Veteran

66 Posts

Posted - 2009-06-03 : 03:10:37
Hi,

How do I Create a Cross Tab query in SQl Server?

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-03 : 03:13:22
If you are using SQL Server 2005, you can try the PIVOT keyword.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Rheinhardt
Yak Posting Veteran

66 Posts

Posted - 2009-06-03 : 03:18:03
Can you maybe ellaborate a bit more...would really aprreciate it.

Thanks Peso!
Go to Top of Page

Rheinhardt
Yak Posting Veteran

66 Posts

Posted - 2009-06-03 : 03:24:03
Example:

Current

Item Date Quantity
12 12/06/2009 200
13 13/07/2009 150

We want:

Item 12/06/2009 13/07/2009
12 200
13 150

We want SQL to pick up the headings of the dates automatically from the normalized data.

Thanks


Go to Top of Page

Rheinhardt
Yak Posting Veteran

66 Posts

Posted - 2009-06-03 : 03:26:54
...Item 12 Quantity of 200 under the respective Date (12/06/2009) and Item 13 quantity 150 under it's respective date (13/07/2009)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-06-03 : 04:02:24
See if this helps
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Rheinhardt
Yak Posting Veteran

66 Posts

Posted - 2009-06-03 : 04:06:42
Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-03 : 12:38:50
if you're using sql 2000 or before or if you've to pivot multiple measures, use this

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx
Go to Top of Page
   

- Advertisement -