--UPDATE
--  dbo.temp_prib_rider_hospital2
--SET
--  Gender = NULL
--WHERE
--  Gender = 'NULL'
  
--UPDATE
--  dbo.temp_prib_rider_hospital2
--SET
--  [Premium Payment Term] = NULL
--WHERE
--  [Premium Payment Term] = 'NULL'

--UPDATE
--  dbo.temp_prib_rider_hospital2
--SET
--  [Occupation Class] = NULL
--WHERE
--  [Occupation Class] = 'NULL'

--UPDATE
--  dbo.temp_prib_rider_hospital2
--SET
--  Risk = NULL
--WHERE
--  Risk = 'NULL'

--UPDATE
--  dbo.temp_prib_rider_hospital2
--SET
--  Policy = NULL
--WHERE
--  Policy = 'NULL'

--UPDATE
--  dbo.temp_prib_rider_hospital2
--SET
--  [Effective Date From] = '2009-05-15 00:00:00.000'
--WHERE
--  [Effective Date From] = '2009-05-01 00:00:00.000'

--UPDATE
--  dbo.temp_prib_rider_hospital2
--SET
--  [Effective Date To] = '2009-05-14 00:00:00.000'
--WHERE
--  [Effective Date To] = '2009-04-30 00:00:00.000'

SELECT
  *
FROM
  dbo.temp_prib_rider_hospital2


---------------------------------------------------------------------
DECLARE @id_row INT

DECLARE list_cursor CURSOR FOR  
SELECT id_row
FROM dbo.temp_prib_rider_hospital2
--WHERE
--  [Rate COI  IT] <> [Rate COI PL]

OPEN list_cursor  
FETCH NEXT FROM list_cursor INTO @id_row  

WHILE @@FETCH_STATUS = 0  
BEGIN  
  
  DECLARE
    @jenis_kelamin VARCHAR(2),
    @thn_ke INT--,
    --@efektif_date DATETIME
    
  SELECT
    @jenis_kelamin = CASE Gender
                        WHEN 'F' THEN 'P'
                        WHEN 'M' THEN 'L'
                        ELSE 'L'  -- bebas
                     END,
    @thn_ke = CASE [Policy Year From]
                WHEN 0 THEN 1
                ELSE [Policy Year From]
              END--,
    --@efektif_date = CASE [Effective Date From]
    --                  WHEN '2009-05-01 00:00:00.000' THEN '2009-05-16 00:00:00.000'
    --                  ELSE [Effective Date From]
    --                END
  FROM
    dbo.temp_prib_rider_hospital2
  WHERE
    id_row = @id_row
  
  BEGIN TRY
  --PRINT @kelas
  --SELECT * FROM dbo.temp_prib_rider_hospital2 WHERE id_row = @id_row
    BEGIN
      UPDATE
        dbo.temp_prib_rider_hospital2
      SET
        [Rate COI  IT] = dbo.func_getpreminew([ID Plan Dasar SQL],[ID Plan Rider SQL],Currency,1,[Occupation Class],Risk,@jenis_kelamin,@jenis_kelamin,[Entry Age From],[Entry Age From],20,[Premium Payment Term],[Sum Assured],[Sum Assured],[Sum Assured],[Sum Assured],20,[Premium Payment Term],[Sum Assured],[Effective Date From],[Effective Date From],[Policy Year From])
        --rate_coi_it_test = dbo.func_getpreminew([ID Plan Dasar SQL],[ID Plan Rider SQL],Currency,1,[Occupation Class],Risk,@jenis_kelamin,@jenis_kelamin,[Entry Age From],[Entry Age From],20,[Premium Payment Term],[Sum Assured],[Sum Assured],[Sum Assured],[Sum Assured],20,[Premium Payment Term],[Sum Assured],@efektif_date,@efektif_date,[Policy Year From])
      FROM
        dbo.temp_prib_rider_hospital2
      WHERE
        id_row = @id_row
    END
  END TRY
  
  BEGIN CATCH
    PRINT @id_row
    -- continue
  END CATCH

  FETCH NEXT FROM list_cursor INTO @id_row  
END  

CLOSE list_cursor  
DEALLOCATE list_cursor 