complex SQL (for me) step 2

hello, Lets look this Proc :

set nocount on
create table Histo
(
Id varchar(10)primary key,
Week varchar(10),
Project varchar(10)
)
insert into Histo (Id, Week, Project)
select '47','2006-12','Internet'
union all
select '48','2006-13','Internet'
union all
select '49','2006-12','Intranet'

go

select*
from Histo

go

SELECT Project,
[2006-12]
,
[2006-13]
FROM
(SELECT Project, week, id
FROM histo) s
PIVOT
(
max(id)
FOR Week IN ([2006-12],[2006-13])
) p
ORDER BY [Project]
go

drop table histo

there are 2 blocks of data "hard coded" ([2006-12], [2006-13]) and I want to have something more elegant.

I want to be able to set a begin week and a number of weeks displayed.

Can anyone help me Thanks a lot





Answer this question

complex SQL (for me) step 2