sql - Cross-tab Query -


I have a table with employee attendance - say - OATT is the following structure and sample data

 AttDate EmpId EmpName AttCode InTime OutTime 01-10-2009 1 Jain, Rahul P 0900 1830 02-10-2009 1 Jain, Rahul P 0900 1830 03-10-2009 1 Jain, Rahul P 0900 1830 04-10-2009 1 Jain, Rahul P 0900 1830 05-10-2009 1 Jain, Rahul P 0900 1830 06-10-2009 1 Jain, Rahul, WO 0900 1830 07-10-2009 1 Jain, Rahul Wau 0900 1830 08-10-2009 1 Jain, Rahul P 0900 1830 09-10-2009 1 Jain, Rahul L 0900 1830 10-10-2009 1 Jain, Rahul P 0900 1830 01-10-2009 1 Jain, Rahul A 09 00 1830 

I need the following result:

EmpId 01-10 02-10 03-10 04-10 05-10 1 PPPPP 2 PPPLP3 PPPPA < P> I know that this pivot can be completed using questions, but I need a dynamic query to do this for the dates of a specified range. I'm using SQL Server 2005.

The keyword PIVOT can help, but with that you still need to know that the query What are your columns before running? It generally means running two questions: one column to get a list of names and then actually a second to get your results.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -