
                WITH cte AS (
                        SELECT
                        	case when '520101000000009' is null then (
                                select PayType_id from v_PayType where PayType_SysNick = 'oms' limit 1
                            ) else '520101000000009' end AS pt,
                            CAST('520101200308430' AS bigint) AS EvnPrescr_id,
                            CAST('520101200308291' AS bigint) AS EvnUsluga_pid,
                            CAST(NULL AS bigint) AS res
                 )

                SELECT
                	evnuslugapar_id as "EvnUsluga_id",
                    Error_Code as "Error_Code",
                    Error_Message as "Error_Msg "
                FROM dbo.p_EvnUslugaPar_ins(
                    EvnUslugaPar_pid := (SELECT EvnUsluga_pid FROM cte),
                    Lpu_id := CAST('520101000000001' AS bigint),
                    Server_id := CAST(520101000000001 AS bigint),
                    PersonEvn_id := CAST('520101055491036' AS bigint),
                    EvnUslugaPar_setDT := CAST(NULL AS timestamp),
                    PayType_id := (SELECT pt FROM cte),
                    Usluga_id := CAST(NULL AS bigint),
                    EvnUslugaPar_Kolvo := 1,
                    EvnUslugaPar_isCito := CAST(1 AS bigint),
                    TimetablePar_id := CAST(NULL AS bigint),
                    
                    UslugaPlace_id := CAST(1 AS bigint),
                    LpuSection_uid := CAST(NULL AS bigint),
                    MedPersonal_id := CAST(NULL AS bigint),
                    UslugaComplex_id := CAST('200431' AS bigint),
                    EvnDirection_id := CAST('520101200308432' AS bigint),
                    Diag_id := '6063',
                    EvnUslugaPar_Result := CAST('["200431"]' AS varchar),
                    EvnPrescr_id := (SELECT EvnPrescr_id FROM cte),
                    EvnPrescrTimetable_id := CAST(NULL AS bigint),
                    pmUser_id := CAST('366469832244' AS bigint)
                    );
            
