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?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.