|
naresh0407
Starting Member
30 Posts |
Posted - 2010-11-09 : 11:36:15
|
| Hi All, How to get dates as header in the result . In the below query i am getting header as Second Week instead of that i need to get 8/8/2010 as Header(Dynamic Dates). convert(varchar,dbo.FDiv(Count(Case When Delta>='0' Then EmpNo end),@TotalEmp)*100)+'%' as 'Second Week' FROM SAR_WeekData where WeekStartDate>='8/8/2010' Declare @test table (empno int,MatchingOff varchar(10),atnDate datetime)Insert into @test(empno,MatchingOff,atnDate)select '101','Off','8/1/2010' union allselect '101','17:00','8/2/2010' union allselect '101','17:00','8/3/2010' union allselect '101','16:00','8/4/2010' union allselect '101','16:00','8/5/2010' union allselect '101','16:00','8/6/2010' union allselect '101','16:00','8/7/2010' union allselect '101','16:00','8/8/2010' union allselect '101','Off','8/9/2010' union allselect '101','17:00','8/10/2010' union allselect '101','17:00','8/11/2010' union allselect '101','16:00','8/12/2010' union allselect '101','16:00','8/13/2010' union allselect '101','16:00','8/14/2010' union allselect '101','16:00','8/15/2010' union allselect '101','16:00','8/16/2010' union allselect '101','Off','8/17/2010' union allselect '101','17:00','8/18/2010' union allselect '101','17:00','8/19/2010' union allselect '101','16:00','8/20/2010' union allselect '101','16:00','8/21/2010' union allselect '101','16:00','8/22/2010' union allselect '101','16:00','8/23/2010' union allselect '101','16:00','8/24/2010' union allselect '101','Off','8/25/2010' union allselect '101','17:00','8/26/2010' union allselect '101','17:00','8/27/2010' union allselect '101','16:00','8/28/2010' union allselect '102','Off','8/1/2010' union allselect '102','17:00','8/2/2010' union allselect '102','17:00','8/3/2010' union allselect '102','16:00','8/4/2010' union allselect '102','16:00','8/5/2010' union allselect '102','16:00','8/6/2010' union allselect '102','16:00','8/7/2010' union allselect '102','16:00','8/8/2010' union allselect '102','Off','8/9/2010' union allselect '102','17:00','8/10/2010' union allselect '102','17:00','8/11/2010' union allselect '102','16:00','8/12/2010' union allselect '102','16:00','8/13/2010' union allselect '102','16:00','8/14/2010' union allselect '102','16:00','8/15/2010' union allselect '102','16:00','8/16/2010' union allselect '102','Off','8/17/2010' union allselect '102','17:00','8/18/2010' union allselect '102','17:00','8/19/2010' union allselect '102','16:00','8/20/2010' union allselect '102','16:00','8/21/2010' union allselect '102','16:00','8/22/2010' union allselect '102','16:00','8/23/2010' union allselect '102','16:00','8/24/2010' union allselect '102','Off','8/25/2010' union allselect '102','17:00','8/26/2010' union allselect '102','21:00','8/27/2010' union allselect '102','16:00','8/28/2010' ALTER procedure [dbo].[SAR_Sp_DeltaFinal](@WeekStartDate datetime,@CampaignID int)asBeginDeclare @TotalEmp int Declare @EndDate datetimeDeclare @StartDate datetimeset @StartDate=dateadd(day,-7,dateadd(day,-7,dateadd(day,-7,@WeekStartDate)))set @EndDate=dateadd(day,6,@WeekStartDate)Declare @Across4weekFinal table (empno int,DeltaAcross4Week decimal(3,2))Declare @Across3weekFinal table (empno int,DeltaAcross3Week decimal(3,2))Declare @Across2weekFinal table (empno int,DeltaAcross2Week decimal(3,2))insert into @Across4weekFinalExec SAR_Sp_DeltaAcross4week @WeekStartDate,1insert into @Across3weekFinalExec SAR_Sp_DeltaAcross3week @WeekStartDate,@CampaignIDinsert into @Across2weekFinalExec SAR_Sp_DeltaAcross2week @WeekStartDate,@CampaignIDSelect @TotalEmp=2Select 'With 2 Hrs' as [Delta in Start Time],convert(varchar (10),dbo.FDiv((Select count(empno) from @Across4weekFinal where DeltaAcross4Week<=2.0) ,@TotalEmp)*100)+' %' as [Across Last 4 Weeks], convert(varchar (10),dbo.FDiv((Select count(empno) from @Across3weekFinal where DeltaAcross3Week<=2.0) ,@TotalEmp)*100)+' %' as [Across Last 3 Weeks],convert(varchar (10),dbo.FDiv((Select count(empno) from @Across2weekFinal where DeltaAcross2Week<=2.0),@TotalEmp)*100)+' %' as [Across Last 2 Weeks],convert(varchar,dbo.FDiv(Count(Case When Delta<='0' Then EmpNo end),@TotalEmp)*100)+'%' as 'First Week' FROM SAR_WeekData where WeekStartDate='8/1/2010',convert(varchar,dbo.FDiv(Count(Case When Delta>='0' Then EmpNo end),@TotalEmp)*100)+'%' as 'Second Week' FROM SAR_WeekData where WeekStartDate>='8/8/2010'End |
|