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.
Author |
Topic |
shohan_db
Starting Member
36 Posts |
Posted - 2006-09-02 : 04:33:54
|
Crosstab conceptsI m using Sql server 2000 version I want to create a simple crosstab… as like the followsMy table is as like Date warehouse (WH) Delivery No7/7/2006 10 10-1 7/7/2006 20 20-17/7/2006 20 20-27/7/2006 30 30-18/7/2006 10 10-28/7/2006 10 10-311/7/2006 30 30-211/7/2006 20 20-3 I want to make a report using crosstab in iReport….. I want report will be as like Date WH10 WH20 WH30 total delivery7/7/2006 1 2 1 48/7/2006 2 0 0 211/7/2006 0 1 1 2 my questions are: i create a crosstab procedure and it is running but01. I want to know the query.02. How I count/sum the wh in the crosstab? (cause the WH is arrange as row in my database table )I want step by step instructions I have not clear concepts about crosstab, but I know crosstab will give the solution of this problem Please help…… Thanks shohan |
|
magnetica
Starting Member
36 Posts |
Posted - 2006-09-02 : 05:47:13
|
I havnt look at all five threads but they look exactly the same. Why?If you think you know it all?! You know nothing! |
 |
|
Rishi Maini SQL2K5 Admin
Yak Posting Veteran
80 Posts |
Posted - 2006-09-02 : 06:13:55
|
CREATE TABLE [dbo].[Table1] ( [DOD] [datetime] NOT NULL , [WH] [int] NULL ) ON [PRIMARY]GOselect * from table1DOD WH ------------------------------------------------------ ----------- 2006-07-07 00:00:00.000 102006-07-07 00:00:00.000 202006-07-07 00:00:00.000 202006-07-07 00:00:00.000 302006-08-07 00:00:00.000 102006-08-07 00:00:00.000 102006-11-07 00:00:00.000 302006-11-07 00:00:00.000 20select DOD, sum( case wh when 10 then 1 else 0 end ) as '10', sum( case wh when 20 then 1 else 0 end ) as '20', sum( case wh when 30 then 1 else 0 end ) as '30',( sum( case wh when 10 then 1 else 0 end ) + sum( case wh when 20 then 1 else 0 end ) + sum( case wh when 30 then 1 else 0 end )) as 'Total'from table1Group by DODDOD 10 20 30 Total ------------------------------------------------------ ----------- ----------- ----------- ----------- 2006-07-07 00:00:00.000 1 2 1 42006-08-07 00:00:00.000 2 0 0 22006-11-07 00:00:00.000 0 1 1 2(3 row(s) affected)ThanksRishi Maini |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|