USE [GrpInsurance]
GO

DECLARE	@return_value int

EXEC	@return_value = [dbo].[proc_Rep90111_kodecabang]
		@NoProposal = N'2012.0820',
		@KomulatifYa = 1,
		@KaryawanYa = 1,
		@KeluargaYa = 1,
		@PriaYa = 1,
		@WanitaYa = 1,
		@Cabang = ''

SELECT	'Return Value' = @return_value

SELECT     TOP 100 PERCENT TmpInsurance.dbo.Rep10358.*, dbo.Cabang.Kode AS Kode_Cabang, dbo.Cabang.Nama AS Cabang, dbo.Kartu_Peserta.Card_No
INTO TmpInsurance.dbo.rep10358_pri
FROM         TmpInsurance.dbo.Rep10358 INNER JOIN
                      dbo.Peserta ON TmpInsurance.dbo.Rep10358.No_Peserta = dbo.Peserta.No_Peserta AND 
                      TmpInsurance.dbo.Rep10358.No_Proposal = dbo.Peserta.No_Proposal INNER JOIN
                      dbo.Sebagai ON dbo.Peserta.Sebagai = dbo.Sebagai.IDI LEFT OUTER JOIN
                      dbo.Kartu_Peserta ON TmpInsurance.dbo.Rep10358.No_Proposal = dbo.Kartu_Peserta.No_Proposal AND 
                      dbo.Peserta.No_Peserta = dbo.Kartu_Peserta.No_Peserta LEFT OUTER JOIN
                      dbo.Cabang ON dbo.Peserta.No_Prs = dbo.Cabang.No_Prs AND dbo.Peserta.Cabang = dbo.Cabang.Kode
--WHERE (dbo.Cabang.Nama LIKE '%'+@Cabang+'%' OR isnull(@Cabang,'')='')
ORDER BY TmpInsurance.dbo.Rep10358.No_Peserta


GO
