Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

yearly sales data for multiple years

Status
Not open for further replies.

memcom

MIS
Nov 19, 2002
56
US
Is there a way to create a view that will show data in a column for 2001 sales, 2002 sales or 2003 sales based on the order_date field?
 
This is the select statement to sum up the data order in one particular year.

create table orde(Data int,Order_date datetime)

insert into orde select 1, '2001-01-12'
insert into orde select 1, '2001-04-12'
insert into orde select 1, '2002-06-12'
insert into orde select 1, '2002-03-12'
insert into orde select 1, '2002-12-12'
insert into orde select 1, '2003-11-12'
insert into orde select 1, '2003-09-12'
insert into orde select 1, '2003-04-12'

select
sum(case when year(order_date) = 2001 then data else '' end) as [2001 sales],
sum(case when year(order_date) = 2002 then data else '' end) as [2002 sales],
sum(case when year(order_date) = 2003 then data else '' end) as [2003 sales]
from orde
 
That works great in query analyzer, but when I try to use it in a view, I get an error saying "The Query Designer does not support the case SQL contruct" Are there any alternatives that I can use for an sql view?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top