USE [GrpInsurance]
GO
/****** Object:  UserDefinedFunction [dbo].[func_GetVendorKlaimRegister]    Script Date: 09/12/2014 11:07:39 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
-- gproc_SetPermission
-- modified by Pribadi Pamungkas, 2014-09-12

CREATE FUNCTION [dbo].[func_GetVendorKlaimRegister] (
       @Id VARCHAR(20),
       @Jenis INT
      )
RETURNS VARCHAR(60)
    BEGIN
        DECLARE @Hasil VARCHAR(100)
        IF @Jenis = 1 OR @Jenis = 3 OR @Jenis = 4 
           SELECT
            @Hasil = T2.Nama_Perusahaan
           FROM
            dbo.Polis_Asuransi T1
            INNER JOIN dbo.Perusahaan T2
            ON T1.No_Prs = T2.No_Prs
           WHERE
            --T1.Active_Ya = 1 AND 
            --T1.No_proposal = @Id
            T1.No_Polis = @Id     -- by Prib, 2014-09-02
            AND T1.Active_Ya = 1  -- by Prib, 2014-09-02
        ELSE 
           SELECT
            @Hasil = Nama
           FROM
            Provider
           WHERE
            IDI = @Id
        RETURN(@Hasil)
    END
