
                    select
                        FIP.FormalizedInspectionParams_SysNick as nick,
                        RVT.RateValueType_SysNick as "RateValueType_SysNick",
                        CASE RVT.RateValueType_SysNick
                            WHEN 'int' THEN cast(FIDATA.FormalizedInspection_NResult as varchar)
                            WHEN 'float' THEN cast(cast(FIDATA.FormalizedInspection_NResult as decimal(16,3)) as varchar)
                            WHEN 'string' THEN cast(FIDATA.FormalizedInspection_NResult as varchar)
                            WHEN 'template' THEN cast(FIDATA.FormalizedInspection_NResult as varchar)
                            WHEN 'reference' THEN cast(FIDATA.FormalizedInspection_NResult as varchar)
                        END as value
                    from v_FormalizedInspectionParams FIP
                    left join RateValueType RVT  on RVT.RateValueType_id = FIP.RateValueType_id
                    left join lateral(
                            select
                                FI.FormalizedInspection_id,
                                FI.FormalizedInspection_NResult
                            from
                                v_FormalizedInspection FI
                            where FI.FormalizedInspectionParams_id = FIP.FormalizedInspectionParams_id and FI.EvnUslugaDispDop_id in (520101201517386, 520101201517552, 520101201517621, 520101201517674, 520101201517753)
                            limit 1
                        ) FIDATA on true
                    where coalesce(FIDATA.FormalizedInspection_id, -1) <> -1
                
