DECLARE @id_peserta VARCHAR(12)
DECLARE @no_peserta VARCHAR(15)

DECLARE list_cursor CURSOR FAST_FORWARD FOR  
SELECT id_peserta, no_peserta
FROM peserta 

OPEN list_cursor  
FETCH NEXT FROM list_cursor INTO @id_peserta, @no_peserta 

WHILE @@FETCH_STATUS = 0  
BEGIN  
  DECLARE @awal VARCHAR(15)
  
  -- list semua nomor peserta, ambil hanya karakter sebelum tanda '-' saja
  SELECT @awal=item FROM dbo.func_explode(@no_peserta,'-') WHERE ItemNumber=1

  -- jika jumlah karakter kurang dari 5
  IF (LEN(@awal)<5)
    BEGIN
    
      UPDATE
        dbo.peserta
      SET
        no_peserta = '0' + @no_peserta  -- tambahkan 0 didepan nomor peserta
      WHERE
        id_peserta = @id_peserta
        
    END 

  FETCH NEXT FROM list_cursor INTO @id_peserta, @no_peserta   
END  

CLOSE list_cursor  
DEALLOCATE list_cursor 