
                
                
                SELECT 
                SLP.ServiceListPackage_id as "ServiceListPackage_id",
                SLP.ServiceListPackage_ObjectID as "ServiceListPackage_ObjectID",
                SLP.ServiceListPackage_GUID as "ServiceListPackage_GUID",
                to_char(SLP.ServiceListPackage_insDT, 'DD.MM.YYYY HH24:MI:SS') as "ServiceListPackage_insDT",
                SLP.ServiceListPackage_IsNotSend as "ServiceListPackage_IsNotSend",
                SLPT.ServiceListPackageType_Description as "ServiceListPackageType_Description",
                SLPDT.ServiceListProcDataType_Name as "ServiceListProcDataType_Name",
                PRT.PackageRouteType_id as "PackageRouteType_id",
                PRT.PackageRouteType_Name as "PackageRouteType_Name",
                PRT.PackageRouteType_SysNick as "PackageRouteType_SysNick",
                PS.PackageStatus_id as "PackageStatus_id",
                PS.PackageStatus_Name as "PackageStatus_Name",
                PS.PackageStatus_SysNick as "PackageStatus_SysNick",
                SP_Request.ServicePackage_Data as "RequestData",
                SP_Response.ServicePackage_Data as "ResponseData"
                
                ,SLDL.ServiceListDetailLog_Message as "ServiceListProcDataType_Result"
            
                
                FROM
                
                stg.v_ServiceListPackage SLP
                left join stg.v_ServiceListPackageType SLPT on SLPT.ServiceListPackageType_id = SLP.ServiceListPackageType_id
                left join stg.v_ServiceListProcDataType SLPDT on SLPDT.ServiceListProcDataType_id = SLP.ServiceListProcDataType_id
                left join stg.v_PackageRouteType PRT on PRT.PackageRouteType_id = SLPT.PackageRouteType_id
                left join stg.v_PackageStatus PS on PS.PackageStatus_id = SLP.PackageStatus_id
                
                left join lateral (
                    select SLDL.*
                    from stg.v_ServiceListDetailLog SLDL
                    where SLDL.ServiceListPackage_id = SLP.ServiceListPackage_id
                    order by SLDL.ServiceListDetailLog_id desc
                    limit 1
                ) SLDL on true
            
                left join lateral (
                    select SP.ServicePackage_Data
                    from stg.v_ServicePackage SP
                    where SP.ServiceListPackage_id = SLP.ServiceListPackage_id
                    and (SP.ServicePackage_IsResp is null or SP.ServicePackage_IsResp = 1)
                    ORDER BY SP.ServicePackage_insDT DESC
                    limit 1
                ) SP_Request on true
                left join lateral (
                    select SP.ServicePackage_Data
                    from stg.v_ServicePackage SP
                    where SP.ServiceListPackage_id = SLP.ServiceListPackage_id
                    and SP.ServicePackage_IsResp = 2
                    ORDER BY SP.ServicePackage_insDT DESC
                    limit 1
                ) SP_Response on true
                 WHERE 
                SLP.ServiceListLog_id = '520101000000846'
and SLP.Lpu_id = '5583219'
                
                
                        ORDER BY
                            
                SLP.ServiceListPackage_insDT
                
                OFFSET 0 ROWS
                FETCH NEXT 100 ROWS ONLY
                
