SELECT
	*
FROM
	dbo.Note_Lunas_Master
WHERE 
  No_Ref='2015.000151'


--DECLARE
--  @tahun SMALLINT = 2015,
--  @bulan TINYINT = 1
--SELECT
--	*
--FROM
--	dbo.Note_Lunas_Master
--WHERE
--  YEAR(Tgl_Bayar) = @tahun
--  AND MONTH(Tgl_Bayar) = @bulan
--  AND No_Ref IN (
--                  SELECT
--	                  No_Ref
--                  FROM
--	                  dbo.Note_Terbit_Master
--                  WHERE
--                    status NOT IN ('C', 'G')
--                    AND YEAR(Tgl_Buat) >= @tahun
--                    AND MONTH(Tgl_Buat) <= @bulan
--                    AND Jenis = 1 -- Tagihan Premi New Bisnis
--                 )
----------------
SELECT
  no_ref,
  MAX(tgl_bayar) AS tgl_lunas,
  SUM(jumlah) AS jml_lunas
FROM
  note_lunas_master
WHERE
  --status <> 'C'
  --AND 
  MONTH(Tgl_Bayar) = 1
  AND YEAR(Tgl_Bayar) = 2015
  AND No_Ref = '2015.000151'
GROUP BY
  no_ref