/*DECLARE @empid_requester VARCHAR(8) = '00001359' DECLARE @now VARCHAR(8) = dbo.fn_formatdatetime(GETDATE(), 'yyyymmdd') DECLARE @AppraisalPeriod VARCHAR(8) = 'F023'*/
DECLARE @StartDate VARCHAR(8) DECLARE @EndDate VARCHAR(8) DECLARE @Sequence VARCHAR(8) 
SELECT 
  @StartDate = Startdate, 
  @EndDate = Enddate 
FROM 
  dbo.PCMAPPPERIOD 
WHERE 
  code = @AppraisalPeriod 
SELECT 
  @Sequence = Sequence 
FROM 
  dbo.PHRPA0047 
WHERE 
  EmployeeID = @empid_requester 
  AND StartDate = @StartDate 
  AND EndDate = @EndDate 
  AND AppraisalType = 'G' 
SELECT  
  0 AS App1Level_51, 
  0 AS App2Level_51, 
  0 AS App3Level_51, 
  0 AS App4Level_51, 
  0 AS App5Level_51, 
  0 AS App6Level_51, 
  0 AS App7Level_51, 
  0 AS App8Level_51, 
  0 AS App9Level_51, 
  0 AS App10Level_51, 
  0 AS App1Score_51, 
  0 AS App2Score_51, 
  0 AS App3Score_51, 
  0 AS App4Score_51, 
  0 AS App5Score_51, 
  0 AS App6Score_51, 
  0 AS App7Score_51, 
  0 AS App8Score_51, 
  0 AS App9Score_51,
  0 AS App10Score_51,
  0 AS App1Percentage_51, 
  0 AS App2Percentage_51, 
  0 AS App3Percentage_51, 
  0 AS App4Percentage_51, 
  0 AS App5Percentage_51, 
  0 AS App6Percentage_51, 
  0 AS App7Percentage_51, 
  0 AS App8Percentage_51, 
  0 AS App9Percentage_51, 
  0 AS App10Percentage_51, 
  'F' AS AppraisalType_51, 
  0 AS Asesor2, 
  0 AS Asesor3, 
  pa51.[Description] AS Description_51, 
  pa51.EmployeeID AS EmployeeID_51, 
  (
    SELECT 
      ISNULL(
        MAX(Sequence) + 1, 
        1
      ) 
    FROM 
      dbo.PHRPA0047 
    WHERE 
      EmployeeID = @empid_requester 
  ) AS HeaderSequence_51, 
  pa51.[Sequence] AS Sequence_51, 
  pa51.SequenceSub AS SequenceSub_51, 
  0 AS SelfPercentage_51, 
  pa51.[Weight] AS Weight_51, 
  0 AS WeightedScore_51, 
  0 AS Asesor1, 
  pa51.QualificationGroup AS QualificationGroup_51, 
  pa51.QualificationID AS QualificationID_51, 
  0 AS CompetencyModel, 
  0 AS LevelAtPlanning_51, 
  0 AS Gap_51, 
  0 AS TargetLevel_51, 
  0 AS ActionPlan_51, 
  0 AS SelfScore_51, 
  pa51.Notes AS Notes_51, 
  0 AS AppraiserScore_51, 
  0 AS TotalPoint_51, 
  0 AS LevelAfterAppraisal_51
FROM 
  dbo.PHRPA0051 pa51 
WHERE 
  pa51.EmployeeID = @empid_requester 
  AND pa51.AppraisalType = 'G' 
  AND pa51.HeaderSequence = @Sequence
  --AND pa51.QualificationGroup = '00000002'
