Calculate Percentage difference-Derived tables

  • Hello,

    How are you today?

    I run the following SQL statement:

    SELECT Book1.COUNTRY, DatePart('yyyy',[ARRIVAL_DATE],1,0), Book1.ED_CARD

    FROM Book1

    ORDER BY 2 ASC, 1 ASC

    which produces the following output:

    Country 2002 2003

    AUSTRALIA 45 50

    AUSTRIA 2 4

    I wish to calculate the percentage difference between years, (2003figure-2002figure)/2002figure * 100

    I figure I can use a derived table but I am not sure how to proceed.

    Can you assist?

  • Hi blinton25,

    quote:


    SELECT Book1.COUNTRY, DatePart('yyyy',[ARRIVAL_DATE],1,0), Book1.ED_CARD

    FROM Book1

    ORDER BY 2 ASC, 1 ASC

    which produces the following output:

    Country 2002 2003

    AUSTRALIA 45 50

    AUSTRIA 2 4

    I wish to calculate the percentage difference between years, (2003figure-2002figure)/2002figure * 100


    well, from scratch I would say, you don't need a derived table.

    Something like

    SELECT Book1.COUNTRY, DatePart(yyyy,ARRIVAL_DATE), Book1.ED_CARD,

    (DatePart(yyyy,ARRIVAL_DATE)-Book1.ED_CARD)/Book1.ED_CARD*100 AS whatever

    FROM Book1

    ORDER BY 2 ASC, 1 ASC

    should work. Maybe you need to modify a little bit, because I haven't tested.

    Cheers,

    Frank

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply