CREATE OR ALTER VIEW pricing.plpr AS
SELECT
    yaplnt plnt,
    LTRIM(RTRIM(a9)) AS comp,
    a30 AS descr,
    SUBSTRING(a249, 242, 2) curr,
    SUBSTRING(a249, 32, 4) AS gl,
    SUBSTRING(a249, 190, 4) AS ar,
    SUBSTRING(a249, 182, 4) AS ap,
    SUBSTRING(a249, 198, 4) AS fa,
    SUBSTRING(a249, 238, 4) AS ic
FROM
    CMSInterfaceIN.lgdat.plnt
    INNER JOIN CMSInterfaceIN.lgdat.code ON
        yacomp = LTRIM(RTRIM(a9))
    LEFT OUTER JOIN CMSInterfaceIN.lgdat.name ON
        'C0000' + LTRIM(RTRIM(a9)) = a7
WHERE
    a2 = 'AA'
    OR a2 IS NULL;
