cross tab or derived table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mirth

    cross tab or derived table

    Ok. thanks guys. I have already read the above website. The current
    status is something like this. There will be more columns in the final
    table but it will give you an idea. It's very much a work in progress.

    DROP TABLE #SummaryTempTab le
    CREATE TABLE #SummaryTempTab le (
    [GLD_ACCTNG_PER] INT,
    [External Sales] decimal,
    [Internal Sales] decimal,
    [Mark Up] decimal
    )

    INSERT INTO #SummaryTempTab le
    SELECT GLD_ACCTNG_PER,
    SUM(CASE WHEN (ACT_GL_NO between '4000' and '4399') THEN GLD_Total
    ELSE 0 END) as 'External Sales',
    SUM(CASE WHEN ((ACT_GL_NO between '4400' and '4499') and (ACT_GL_NO
    <> '4400')) THEN GLD_Total ELSE 0 END) as 'Internal Sales',
    SUM(CASE WHEN (ACT_GL_NO = '4400') THEN GLD_Total ELSE 0 END) as
    'Mark Up'
    FROM FinancePeriod
    WHERE ([coid] = 'SPL') AND (GLD_SSN_BRH = 'CUM') AND (GLD_ACCTNG_PER
    like '2004%') AND ACT_GL_NO BETWEEN 4000 AND 9999
    GROUP BY GLD_ACCTNG_PER

    The select statement gives data like this....

    Period External Sales Internal Sales Mark Up
    200301 -1287015 -4006 -202543
    200302 -1771901 -8053 -350049
    200303 -1831843 -9412 -215212
    200304 -1193717 -1824 -103048
    200305 -1450486 -5807 -242358


    I need the output to look like this....

    200301 200302 200303 200304 200305
    External Sales -1287015 -1771901 -1831843 -1193717 -1450486
    Internal Sales -4006 -8053 -9412 -1824 -5807
    Mark Up -202543 -350049 -215212 -103048 -242358

    I hope this helps explain a little better what I'm trying to do.
Working...