
             WITH cte AS (
                SELECT
                    cast(NULL as bigint) AS res,
                    CASE WHEN NULL IS NOT NULL THEN NULL ELSE (SELECT morbus_id FROM v_EvnVizitPL WHERE EvnVizitPL_id = '520101354185873' LIMIT 1) END AS morbus_id
            )
            select
            	EvnUslugaCommon_id as "EvnUslugaCommon_id",
                Error_Code as "Error_Code",
                Error_Message as "Error_Msg"
            from dbo.p_EvnUslugaCommon_ins(
            	EvnUslugaCommon_id := (select res from cte),
                EvnUslugaCommon_pid := '520101354185873',
                Lpu_id := '2867',
                Server_id := 2867,
                PersonEvn_id := '520101071525266',
                EvnUslugaCommon_setDT := '2023-07-19 08:08',
                EvnUslugaCommon_disDT := '2023-07-19 08:08',
                PayType_id := '520101000000009',
                Usluga_id := NULL,
                UslugaComplex_id := '206678',
                MedSpecOms_id := NULL,
                LpuSectionProfile_id := '520101000000148',
                MedPersonal_id := '520101000017839',
                MedStaffFact_id := '520101000107134',
                MedStaffFact_sid := NULL,
                UslugaPlace_id := '1',
                Lpu_uid := NULL,
                LpuSection_uid := '520101000008880',
                Org_uid := NULL,
                EvnUslugaCommon_Kolvo := 1,
                Morbus_id := (select morbus_id from cte),
                EvnUslugaCommon_CoeffTariff := NULL,
                EvnUslugaCommon_IsModern := NULL,
                MesOperType_id := NULL,
                UslugaComplexTariff_id := NULL,
                DiagSetClass_id := NULL,
                Diag_id := NULL,
                EvnUslugaCommon_Price := NULL,
                EvnUslugaCommon_Summa := NULL,
                EvnPrescr_id := NULL,
                EvnUslugaCommon_IsVizitCode := NULL,
                EvnUslugaCommon_IsMinusUsluga := 1,
                EvnDirection_id := NULL,
                UslugaExecutionType_id := NULL,
                UslugaExecutionReason_id := NULL,
                pmUser_id := '387056096169');
        
