Hello Expert!
I need help to I translate this data...
Table "LeaveDetail"
StaffNo | StartDate | EndDate | LeaveType |
1 | 23/04/2006 | 26/04/2006 | AL |
2 | 24/04/2006 | 25/04/2006 | MC |
3 | 26/04/2006 | 27/04/2006 | EL |
1 | 30/04/2006 | 02/05/2006 | EL |
Into this format...
|Apr|Apr|Apr|Apr|Apr|Apr|Apr|Apr|May|May|May|May|
StaffNo |23 |24 |25 |26 |27 |28 |29 |30 |01 |02 |03 |04..
---------------------------------------------------------
1 |AL |AL |AL |AL | | ... |EL |EL |EL |
2 | |MC |MC | | |
3 | | | |EL |EL |
Parameter:
Date From e.g. 23/04/2006 to 23/05/2006
Using only query statement...
Is this possible
TIA
Regards.

How to format leave detail into tabular/pivot format?
Phil
I forgot to mention I’m using MS SQL Server 7
I found similar solution in MS Access. All done with 1 Table for days + query to convert to pivot/crosstab format, no coding in client side and no formatting in reporting tool needed
e.g.
TblDay e.g.: 1,2,3,4....31
The query:
PARAMETERS [Enter Month] Text ( 255 ), [Enter Year] Text ( 255 );
TRANSFORM First(LeaveDetail.LeaveType) AS FirstOfLeaveType
SELECT EmpNo
FROM tblDays, LeaveDetail
WHERE DateSerial([Enter Year],[Enter Month],[Day])) Between [LeaveDetail].[dStartDate] And [LeaveDetail].[dEndDate]
GROUP BY EmpNo
ORDER BY EmpNo
PIVOT tblDays.Day In (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31);
The result will look like this:
StaffNo |1 |2 |3 |4 |5 |6 |7 |8 |9 |10 |11 |12..
---------------------------------------------------------
1 |AL |AL |AL |AL | | ... |EL |EL |EL |
I know there are no such functions for tabular format in SQL Server 7, so I’m here to find similar solution that producing result as I have mention earlier which not depend on client or reporting tool
Is this possible
Chris Powell
Hmm..
No I don' have, appreciate if you can guide me on that
MathiasWestin
this thing looks like a cross tab queries.
maybe some examples from here will help.
http://www.sqlmag.com/Article/ArticleID/15608/15608.html
pls see the zip files
here some more
http://www.sqlteam.com/item.asp ItemID=2955
you have do it thru dynamic query
Nihar
HTH, Jens Suessmeyer.
---
http://www.sqlserver2005.de
---
Guino
Fendy
Thanks, I'll try
Regards