SELECT
  *
FROM 
  Polis_Rekening
GROUP BY
  No_Polis

SELECT 
  Rek_Nama2,
  Kode_Bank2,
  Rek_No2,
  * 
FROM 
  Polis_Rekening
WHERE 
  No_Polis = ''
  
SELECT * FROM Bank_Master

SELECT
	*
FROM
	Note_Lunas_Master
WHERE
  No_Ref = '2015.046659'

SELECT
	*
FROM
	dbo.Bank_Asal AS ba

SELECT
  dbo.Note_Lunas_Master.No_Ref,
  dbo.Note_Lunas_Master.Create_Date,
  dbo.Note_Lunas_Master.Tgl_Bayar,
  dbo.Note_Terbit_Master.No_Note,
  dbo.Note_Terbit_Master.Tipe,
  dbo.Polis_Asuransi.No_Proposal,
  dbo.Note_Terbit_Master.Total,
  dbo.Note_Terbit_Master.Jml_Adjust,
  dbo.Note_Lunas_Master.No_Bukti,
  dbo.Note_Lunas_Master.Rek_No,
  dbo.Note_Lunas_Master.Cicilan_Ke,
  Pelunasan = CASE dbo.Note_Terbit_Master.Write_Off
                WHEN 1 THEN dbo.Note_Terbit_Master.Tipe * SUM(dbo.Note_Terbit_Master.Jml_Adjust)
                ELSE dbo.Note_Terbit_Master.Tipe * SUM(dbo.Note_Lunas_Master.Jumlah)
              END,
  dbo.Note_Terbit_Master.Write_Off,
  pr.Rek_No2,
  pr.Rek_Nama2,
  pr.Kode_Bank2,
  bm.Nama_Bank
FROM
  dbo.Note_Lunas_Master
  INNER JOIN dbo.Note_Terbit_Master ON dbo.Note_Lunas_Master.No_Ref = dbo.Note_Terbit_Master.No_Ref
  INNER JOIN dbo.Polis_Asuransi ON dbo.Note_Terbit_Master.No_Proposal = dbo.Polis_Asuransi.No_Proposal
  INNER JOIN dbo.Perusahaan ON dbo.Polis_Asuransi.No_Prs = dbo.Perusahaan.No_Prs
  LEFT JOIN dbo.Polis_Rekening AS pr ON dbo.Polis_Asuransi.No_Polis = pr.No_Polis
  LEFT JOIN dbo.Bank_Master AS bm ON pr.Kode_Bank2 = bm.Kode_Bank
WHERE
  dbo.Note_Lunas_Master.No_Ref = '2015.046659'
GROUP BY
  dbo.Note_Lunas_Master.No_Ref,
  dbo.Note_Lunas_Master.Create_Date,
  dbo.Note_Lunas_Master.Tgl_Bayar,
  dbo.Note_Terbit_Master.No_Note,
  dbo.Note_Terbit_Master.Tipe,
  dbo.Polis_Asuransi.No_Proposal,
  dbo.Note_Terbit_Master.Total,
  dbo.Note_Terbit_Master.Jml_Adjust,
  dbo.Note_Lunas_Master.No_Bukti,
  dbo.Note_Lunas_Master.Rek_No,
  dbo.Note_Lunas_Master.Cicilan_Ke,
  dbo.Note_Terbit_Master.Write_Off,
  pr.Rek_No2,
  pr.Rek_Nama2,
  pr.Kode_Bank2,
  bm.Nama_Bank
