August 9, 2010 at 5:49 am
Hello,
I have a table Orders
By applying sql query on it I am getting result set(table) as follows
sum(freight) | YEAR(orderdate)
-------------+------------------
----------- +------------------
25000 + 1997
-------------+------------------
30000 + 1998
Now I want to use 1997's sum(freight) as Target and 1998's sum(freight) as Current.My query should be such that it will fetch following resultset.
Target | Current
----------------
25000 | 30000
Please can anyone help me with the query?
Regards,
Snehalata
August 9, 2010 at 6:04 am
snehalata_d (8/9/2010)
Hello,I have a table Orders
By applying sql query on it I am getting result set(table) as follows
sum(freight) | YEAR(orderdate)
-------------+------------------
----------- +------------------
25000 + 1997
-------------+------------------
30000 + 1998
Now I want to use 1997's sum(freight) as Target and 1998's sum(freight) as Current.My query should be such that it will fetch following resultset.
Target | Current
----------------
25000 | 30000
Please can anyone help me with the query?
Regards,
Snehalata
This is a pivot query, see Pivot in books online, or better still check out this excellent article by Jeff Moden:
http://www.sqlservercentral.com/articles/T-SQL/63681/[/url]
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
August 9, 2010 at 6:07 am
You have to use pivot table
August 10, 2010 at 1:04 am
Thanks a lot.
With the help of the useful article ,I was able to solve my problem.:-)
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply