--PREMI

--If Jenis in [4,12,7,6,11] Then
--  If (Jenis in [4,12,7]) Then
--    If Jenis in [4,12] Then QRlbTitle.Caption:='DAFTAR PERUBAHAN PREMI PESERTA'
--                      Else QRlbTitle.Caption:='DAFTAR PERUBAHAN PREMI PESERTA';
--    Else If Jenis in [6,11]  Then
--      QRlbTitle.Caption:='DAFTAR PESERTA KELUAR';
  SELECT
    Peserta_Produk_Detail.*,
    Peserta_Produk_Detail.Tgl_Ubah AS TglKeluar,
    Peserta.Cabang,
    Note_Terbit_Master.Mata_Uang,
    Peserta.NIK,
    Peserta.Departemen,
    Peserta.Nama + ISNULL(Peserta.NIK, '') AS Nama
  FROM
    (Peserta_Produk_Detail
    INNER JOIN Peserta ON Peserta_Produk_Detail.No_Peserta = Peserta.No_Peserta
                          AND Peserta_Produk_Detail.No_Proposal = Peserta.No_Proposal)
    INNER JOIN Note_Terbit_Master ON Peserta_Produk_Detail.No_Ref = Note_Terbit_Master.No_Ref
  WHERE
    (Peserta_Produk_Detail.No_Ref = '2015.088282')
  ORDER BY
    Peserta_Produk_Detail.No_Peserta
--Else
  SELECT
    Peserta_Produk_Detail.*,
    Peserta_Produk_Detail.Usia AS Umr,
    Peserta.Nama + ISNULL(Peserta.Nik, '') AS Nama,
    Peserta.Grade,
    Peserta.Pln
  FROM
    Peserta_Produk_Detail Peserta_Produk_Detail,
    Peserta Peserta
  WHERE
    (Peserta.No_Peserta = Peserta_Produk_Detail.No_Peserta
    AND Peserta.No_Proposal = Peserta_Produk_Detail.No_Proposal)
    AND (Peserta_Produk_Detail.No_Ref = '2015.088282')
  --If Length(Cabang)<>0 Then
  --Begin
  --    SQL.Add('AND (Peserta.Cabang=:Cabang)');
  --End;
  ORDER BY
    Peserta_Produk_Detail.No_Peserta
-----------------------------------------------------------------
SELECT 
  pst.No_Proposal,
  ppd.No_Peserta,
  pst.Nama,
  --pst.Nama + ISNULL(pst.Nik, '') AS Nama,
  pst.Kelamin,
  pst.Status_Kawin,
  ppd.Usia,
  --pst.Grade,
  --pst.Pln,
  sk.Nama_Sub,
  ppd.Kelas,
  ppd.Benefit AS UP,
  ppd.Curr_Premi
FROM
  dbo.Peserta_Produk_Detail AS ppd INNER JOIN
  dbo.Peserta AS pst ON ppd.No_Proposal = pst.No_Proposal
                    AND ppd.No_Peserta = pst.No_Peserta INNER JOIN
  dbo.Sub_Kelompok AS sk ON ppd.Sub_Kelompok = sk.Sub_Kelompok
WHERE
  (ppd.No_Ref = '2015.088282')
--If Length(Cabang)<>0 Then
--Begin
--    SQL.Add('AND (Peserta.Cabang=:Cabang)');
--End;
ORDER BY
  ppd.No_Peserta

SELECT
	*
FROM
	dbo.Peserta_Produk_Detail AS ppd