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

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

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

SELECT
  *
FROM
  dbo.temp_prib_rider
---------------------------------------------------------------------
DECLARE @id_row INT

DECLARE list_cursor CURSOR FOR  
SELECT id_row
FROM dbo.temp_prib_rider

OPEN list_cursor  
FETCH NEXT FROM list_cursor INTO @id_row  

WHILE @@FETCH_STATUS = 0  
BEGIN  
  
  DECLARE
    @id_plan_dasar VARCHAR(20),
    @jenis_kelamin VARCHAR(2),
    @thn_ke INT
    
  SELECT
    @id_plan_dasar = CASE [ID Plan SQL]
                        WHEN '1118' THEN '0195'
                        WHEN '1122' THEN '0195'
                        ELSE '0159'
                     END,
    @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
  FROM
    dbo.temp_prib_rider
  WHERE
    id_row = @id_row
  
  BEGIN TRY
    BEGIN
      UPDATE
        dbo.temp_prib_rider
      SET
        [Rate COI  IT] = dbo.func_getpreminew(@id_plan_dasar,[ID Plan 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],@thn_ke)
      FROM
        dbo.temp_prib_rider
      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 