Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
ALTER PROCEDURE [dbo].[MRDB_CDTS_FACTORY]
@dtdate VARCHAR(50)
AS
BEGIN
CREATE TABLE #TEMP (CITY VARCHAR(MAX),Capability VARCHAR(MAX),
Tool VARCHAR(MAX),Country varchar(max),[GPS Company] VARCHAR(MAX),
[GPS Service Group] VARCHAR(MAX),[GPS Career Track] VARCHAR(MAX),[GPS Rate Descriptor] VARCHAR(MAX),
[GCPM Rate Type] VARCHAR(MAX),[DATA Career Track] VARCHAR(MAX),[DATA Rate Type] VARCHAR(MAX),
[DATA Load Type] VARCHAR(MAX),[LevelOfEmp] VARCHAR(MAX),[Bill Code] VARCHAR(MAX),
[GCPM Bill Rate] VARCHAR(MAX),[PD&S Load] DECIMAL(18,1),[GS Load] DECIMAL(18,1),
[Unloaded Cost Rate] DECIMAL(18,2),[Billable Hours] DECIMAL(18,0),[Utillised Hours] DECIMAL(18,0),
[PD&R] DECIMAL(18,0),[LOADCOST] DECIMAL(18,1))
INSERT INTO #TEMP
SELECT 
       CITY,
       Capability,
       Tool,
       Country,
       [GPS Company],
       [GPS Service Group],
       [GPS Career Track],
       [GPS Rate Descriptor],
       [GCPM Rate Type],
       [DATA Career Track],
       [DATA Rate Type],
       [DATA Load Type],
       [LevelOfEmp],
       [Bill Code],
       [GCPM Bill Rate],
       [PD&S Load],
       [GS Load],
       [Unloaded Cost Rate],
       [Billable Hours],
       [Utillised Hours],
       [PD&R],
       [LOADCOST]
       
  FROM    
       
       
(select 
 distinct(apt.city) AS CITY,
 APT.Capability AS Capability,
 'All' as Tool,      
 apt.country as Country, 
 'Accenture' as [GPS Company],
 'All' as [GPS Service Group], 
 'Services' as [GPS Career Track],
 'Exception -BPO :'+apt.Capability+'-Day-'+apt.Language+'-'+apt.city as [GPS Rate Descriptor],
 '' as [GCPM Rate Type],
 'Services' as [DATA Career Track],
 'Exception -BPO :'+apt.Capability+'-Day-'+apt.Language+'-'+apt.city as [DATA Rate Type],
lds.[Total Low SU]*100 as [Total Low SU],
lds.[Total Medium SU]*100 as [Total Medium SU],
lds.[Total High SU]*100 as [Total High SU],
lds.[Total Accenture Office/Dedicated]*100 as [Total Accenture Office/Dedicated],
lds.[Total Client Provided Facility / WFH]*100 as [Total Client Provided Facility / WFH],
lds.[Total Client provided facility with Tech]*100 as [Total Client provided facility with Tech],
apt.Level as [LevelOfEmp],
'' as [Bill Code],
'' as [GCPM Bill Rate],
99999.0 AS [PD&S Load],
99999.0 AS [GS Load],
apt.currency,CAST((NULLIF(nullif((apt.Regular),0)/nullif((sc.[Billable Hours]),0),0)) AS DECIMAL(18,2)) as [Unloaded Cost Rate], 
CAST(sc.[Billable Hours] as decimal(18,0)) as [Billable Hours],
CAST(sc.[Utillised Hours] as decimal(8,0)) AS [Utillised Hours],
sc.[PD&R] as [PD&R]
FROM AnnualPayRoll_Table apt
join SeatCharge sc on apt.Level=sc.level join Loads lds on lds.Location_Name=sc.country where apt.Capability NOT IN ('Capital Project Management' , 'Emerging - Industry Specific','Emerging Cross Industry') AND APT.Regular <> 0 AND APT.city=SC.CITY
AND apt.Datetime=@dtdate and sc.DATETIME=@dtdate And lds.Location_Name=apt.country
and lds.Center_name=apt.city and lds.Center_name=sc.CITY and apt.Capability=lds.Capability and lds.Datecol=@dtdate 

       
                            
union all

select 
     distinct(apt.city) as CITY,
     apt.Capability as Capability,
     'All' as Tool,
     apt.country as Country,
     'Accenture' as [GPS Company],
     'All' as [GPS Service Group],
     'Services' as [GPS Career Track], 
     'Exception -BPO :'+apt.Capability+'-Night-'+apt.Language+'-'+apt.city as [GPS Rate Descriptor],
     '' as [GCPM Rate Type],
     'Services' as [DATA Career Track],
     'Exception -BPO :'+apt.Capability+'-Night-'+apt.Language+'-'+apt.city as [DATA Rate Type],
     lds.[Total Low SU]*100 as [Total Low SU],
     lds.[Total Medium SU]*100 as [Total Medium SU],
     lds.[Total High SU]*100 as [Total High SU],
     lds.[Total Accenture Office/Dedicated]*100 as [Total Accenture Office/Dedicated],
     lds.[Total Client Provided Facility / WFH]*100 as [Total Client Provided Facility / WFH],
     lds.[Total Client provided facility with Tech]*100 as [Total Client provided facility with Tech],
     apt.Level as [LevelOfEmp],
     '' as [Bill Code],
     '' as [GCPM Bill Rate],
     99999.0 AS [PD&S Load],
     99999.0 AS [GS Load],
     apt.currency,CAST((nullif((apt.Night),0)/nullif((sc.[Billable Hours]),0)) AS DECIMAL(18,2)) as [Unloaded Cost Rate],
      CAST(sc.[Utillised Hours] as decimal(18,0)) as [Utillised Hours],
      CAST(sc.[Billable Hours] as decimal(18,0)) as [Billable Hours],
      sc.[PD&R] as [PD&R]
 from AnnualPayRoll_Table apt
join SeatCharge sc on apt.Level=sc.level join Loads lds on lds.Location_Name=sc.country
  where apt.Capability NOT IN ('Capital Project Management' , 'Emerging - Industry Specific','Emerging Cross Industry') AND APT.Night <> 0 AND APT.city=SC.CITY
and apt.Datetime=@dtdate and sc.DATETIME=@dtdate And lds.Location_Name=apt.country
and lds.Center_name=apt.city and lds.Center_name=sc.CITY and apt.Capability=lds.Capability and lds.Datecol=@dtdate 

 

union all

select 
     distinct(hrsnondcso.Center_name) as CITY,
      
      hrsnondcso.Capability as Capability,
      
      'All' as Tool,
      
    hrsnondcso.Location_Name as Country,
      
     'Accenture' as [GPS Company],
      
     'All' as [GPS Service Group],
      
     'Services' as [GPS Career Track],
      
     'Exception -BPO :'+hrsnondcso.Capability+' '+' ' +' '+hrsnondcso.Center_name as [GPS Rate Descriptor],
      
     '' as [GCPM Rate Type],
      
     'Services' as [DATA Career Track],
      
     'Exception -BPO :'+hrsnondcso.Capability+' '+' '+' '+hrsnondcso.Center_name as [DATA Rate Type],
      
      lds.[Total Low SU]*100 as [Total Low SU],
      lds.[Total Medium SU]*100 as [Total Medium SU],
      lds.[Total High SU]*100 as [Total High SU],
      lds.[Total Accenture Office/Dedicated]*100 as [Total Accenture Office/Dedicated],
      lds.[Total Client Provided Facility / WFH]*100 as [Total Client Provided Facility / WFH],
      lds.[Total Client provided facility with Tech]*100 as [Total Client provided facility with Tech],
      
      hrsnondcso.Level as [LevelOfEmp],
      
     '' as [Bill Code],
     
     '' as [GCPM Bill Rate],
     
     99999.0 AS [PD&S Load],
     
     99999.0 AS [GS Load],
     
     0.00  as [Unloaded Cost Rate],
      
    CAST(hrsnondcso.[Utilised Hours] as decimal(18,0)) as [Utillised Hours],
     
    CAST(hrsnondcso.[Billable Hours] as decimal(18,0))as [Billable Hours],

     hrsnondcso.[PDR Hours] as [PD&R]
      
from Hours_NonDcso hrsnondcso join Loads lds on lds.Location_Name=hrsnondcso.Location_Name
and lds.Center_name=hrsnondcso.Center_name and lds.Capability=hrsnondcso.Capability and hrsnondcso.Datecol=lds.Datecol
where hrsnondcso.Datecol=@dtdate and lds.Datecol=@dtdate 


) p
           
UNPIVOT(   [LOADCOST] FOR [DATA Load Type] IN 
                                         (
                                          [Total Low SU],
                                          [Total Medium SU],
                                          [Total High SU],
                                          [Total Accenture Office/Dedicated],
                                          [Total Client Provided Facility / WFH],
                                          [Total Client provided facility with Tech]
                                          )
                                          
                                          )AS UNPVT ORDER BY CITY,Country,Capability 
                                          




UPDATE #TEMP SET [PD&S Load]=LD.[PDS Low SU]*100 FROM #TEMP TM JOIN Loads LD ON LD.Location_Name=TM.Country and ld.Center_name=tm.CITY and ld.Capability=tm.Capability
where tm.[DATA Load Type]='Total Low SU' and ld.Datecol=@dtdate
UPDATE #TEMP SET [PD&S Load]=LD.[PDS Medium SU]*100 FROM #TEMP TM JOIN Loads LD ON LD.Location_Name=TM.Country and ld.Center_name=tm.CITY and ld.Capability=tm.Capability
where tm.[DATA Load Type]='Total Medium SU' and ld.Datecol=@dtdate
UPDATE #TEMP SET [PD&S Load]=LD.[PDS High SU]*100 FROM #TEMP TM JOIN Loads LD ON LD.Location_Name=TM.Country and ld.Center_name=tm.CITY and ld.Capability=tm.Capability
where tm.[DATA Load Type]='Total High SU' and ld.Datecol=@dtdate
UPDATE #TEMP SET [PD&S Load]=LD.[PDS Accenture Office/Dedicated]*100 FROM #TEMP TM JOIN Loads LD ON LD.Location_Name=TM.Country and ld.Center_name=tm.CITY and ld.Capability=tm.Capability
where tm.[DATA Load Type]='Total Accenture Office/Dedicated' and ld.Datecol=@dtdate
UPDATE #TEMP SET [PD&S Load]=LD.[PDS Client provided facility/WFH]*100 FROM #TEMP TM JOIN Loads LD ON LD.Location_Name=TM.Country and ld.Center_name=tm.CITY and ld.Capability=tm.Capability
where tm.[DATA Load Type]='Total Client Provided Facility / WFH' and ld.Datecol=@dtdate
UPDATE #TEMP SET [PD&S Load]=LD.[GS Client provided facility with Tech]*100 FROM #TEMP TM JOIN Loads LD ON LD.Location_Name=TM.Country and ld.Center_name=tm.CITY and ld.Capability=tm.Capability
where tm.[DATA Load Type]='Total Client provided facility with Tech' and ld.Datecol=@dtdate
select * from #TEMP
END

--exec MRDB_CDTS_FACTORY 'FY-14'


hi i am getting below error...i spend whole day but could not found the mistake i am doing please help me...


Msg 205, Level 16, State 1, Procedure MRDB_CDTS_FACTORY, Line 14
All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.
Posted
Updated 20-Feb-14 9:36am
v2
Comments
Member 10057465 20-Feb-14 1:24am    
Hi sorry guys...found the mistake..unloaded cost in first two select statements may return null and third select statement has zero..
thanks.
thatraja 20-Feb-14 2:40am    
Reply that to answer, see below.

Don't waste the Whole Day,Just google it

Refer why you getting this
 
Share this answer
 
v3
Comments
Maciej Los 20-Feb-14 16:38pm    
Good point!
+5!
King Fisher 20-Feb-14 23:32pm    
thanks
In the second and third sub-query the column [Billable Hours] and [Utilised Hours] are inverse order.

In the third sub-query the collumn "apt.currency" is missing.
 
Share this answer
 
Comments
Andrius Leonavicius 21-Feb-14 14:27pm    
You have a great attention to details. +5 for that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900