Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 query represent result in columns not row by row

Author  Topic 

javad.nikoo
Starting Member

17 Posts

Posted - 2010-10-25 : 06:50:32
Hi
I have a table and it has 2 filed(sale_Count,Sale_Date) i need a query which return one row and it contain 2 columns for each month of year
for example(output need) :
feb 2200$ jan 250$ March 320$ ... december 5000$
but my qurey result is this:
feb 2200$
jan 250$
March 320$
.
.
.
december 5000$

Thanks


vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-10-25 : 07:14:08
You should do it in front end report as it is display issue rather data concerns.

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

vijayakumar_svk
Yak Posting Veteran

50 Posts

Posted - 2010-10-25 : 07:53:51
You can use PIVOT if you wan to do this in query.. Again this will sum the data irrespect of the year so you need to knwo whether you are running this for a specific year.

Eg:

select * from (
select left(datename(month,sale_date),3) as m, sum(sale_count) as s from tsale group by left(datename(month,sale_date),3)) as a
PIVOT
(
sum(s)
FOR [m] IN ([Jan],[Feb],[Mar],[Apr],[May],[Jun],[Jul],[Aug],[Sep],[Oct],[Nov],[Dec])
) as p1

==============================
Work smarter not harder take control of your life be a super achiever
Go to Top of Page
   

- Advertisement -