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 |
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2008-03-04 : 09:29:14
|
| have a table with 3 fields - work type, status,date.we need different worktypes as one column, count of status=pending as second column,count of status=disposedas third column. second and third columns should be grouped by work type.all this information is to be given for a particular period i.e b/w two dates.plz help me to write the sql query thanks cskTable and sample dataCreate Table Work ( Wtype Varchar(10), Status Varchar(10), Wdate Datetime)Insert into Work Select 'A','P',Getdate()+1 Union allSelect 'B','P',Getdate() Union allSelect 'C','D',Getdate()-1 Union allSelect 'D','D',Getdate()+1 Union allSelect 'E','A',Getdate()+1 Union allSelect 'F','A',Getdate() |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-03-04 : 09:31:42
|
| [code]SELECT WorkType, SUM(CASE WHEN status='P' THEN 1 ELSE 0 END) AS PendingCount, SUM(CASE WHEN status='D' THEN 1 ELSE 0 END) AS DisposedCountFROM WorkWhere WDate BETWEEN @Date1 AND @Date2GROUP BY WorkType[/code]@Date1 and @Date2 are parameters holding date values |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2008-03-04 : 09:37:15
|
| Thanks for your quick reply VisakhIt's working fineThanks again |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2008-03-04 : 10:34:02
|
| Any one is it possible to write the same query in Access..?Thankscsk |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-04 : 10:56:39
|
Yes. Replace CASE with IIF function. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2008-03-04 : 11:00:34
|
| Thanks Peso. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-03-05 : 04:02:51
|
| I think ACCESS supports TRANSFORM operatorMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|