Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2003
    Location
    Kuala Lumpur, Malaysia
    Posts
    6

    Question Unanswered: How to do comparison between current_year_amount vs previous_year_amount

    Hi all,

    I try to compare this year amount, A (i.e March 2003) with last year amount, B (i.e March 2002) to get a result, C. I need to calculate and store figure for each following month, then later compute variance from the C value i get.

    May I know how to write SQL code that allow me to have both last year data n this year data in the furure? I only have current year figure now.

    A thousand thanks!

    SQL Junior,
    Suh Fui

  2. #2
    Join Date
    May 2002
    Posts
    299

    Re: How to do comparison between current_year_amount vs previous_year_amount

    Here is a quick demo that you can apply to your issue.

    select sum(case when convert(varchar(6),orderdate,112)='199607' then freight else 0 end) as 'Jul 96',
    sum(case when convert(varchar(6),orderdate,112)='199707' then freight else 0 end) as 'Jul 97'
    from northwind..orders
    --
    -oj
    http://www.rac4sql.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •