Hi experts,
I am working on SQL Server 2005.
Now i have to write a query which will extract some information from a
table.
My main table is having few columns supose 3 columns.
EmpID Supervisor_ID Date_Of_Visit
Now records are entering in this tabl. Date of visit is date of
supervisor vist on which employee supervisor visited his work.
Generally its on monthly basis. A new row is entered in the table on
every visit. But in some cases employee may be visited more than once
may be two times or 10 times depending on the situation, and for each
visit one new row is inserted in the table.
Now i have to extract the information from last one yearppose I am
running this query today In August 2008 then it should show the
employee id and his date of visit from September 2007 to August 2008.
All 12 date of visits should appear in row format.
There will be 13 columns in the result.
One for EmpID and rest 12 for date of visits Starting from DOV1, Dov2
till DOV12. And if there will be more than onve Date_Of_Visit for any
employee then it should come in the same month column seprated by
comma. And if there is no visit in any month then that columns should
appear with null value
for ex
EmpID Supervisor_ID Date_Of_Visit
1 300 20/08/2007
1 300 25/08/2007
1 300 29/08/2007
2 250 21/08/2007
1 300 21/09/2007
2 250 21/09/2007
1 300 21/10/2007
2 250 21/10/2007
1 300 21/11/2007
2 250 21/11/2007
1 300 21/12/2007
2 250 21/12/2007
1 300 21/01/2008
2 250 21/01/2008
1 300 21/02/2008
2 250 21/02/2008
2 250 21/05/2008
1 300 02/08/2008
1 300 11/08/2008
2 250 08/08/2008
2 250 19/08/2008
Now i have to write a query which will give result like below
EmpID DOV1 DOV2 DOV3
DOV4 DOV5 DOV6 DOV7 DOV8 DOV9 DOV10
DOV11 DOV12
1 20/08/2007,25/08/2007,29/08/2007 21/09/2007 21/10/2007
21/11/2007 21/12/2007 21/01/2008 21/02/2008
02/08/2008,11/08/2008
2 21/08/2007 21/09/2007 21/10/2007
21/11/2007 21/12/2007 21/01/2008 21/02/2008
08/08/2008,19/08/2008
How i can get this result, Please help me.
Any help wil be appriciated.
Regards
Dinesh