estructura en sql server

27/10/2004 - 12:34 por eidertxu50 | Informe spam
Hola a tod@s:
Tengo que hacer una consulta en sql server, en el cual lo que me
interesa es obetenr una tabla que tenga como columnas unas franjas
horarias (6-6:29, 6:30-6:59,7-7:290,) y como filas, todos los dias
del año (1 enero, 2 enero,.,1 julio, 2 julio,...). Podria alguien
decirme si hay forma de hacerlo???? Gracias por todo. Un saludo
 

Leer las respuestas

#1 Liliana Sorrentino
27/10/2004 - 15:36 | Informe spam
Hola,
No estoy segura de haber entendido tu necesidad, por las dudas va esto,
espero que sea lo que buscás.
Saludos, Liliana.

drop table #fechas
create table #fechas (fecha char(5))
declare @fecha datetime set @fecha = '19000101'
while year(@fecha) = 1900
begin
insert #fechas
select convert(char(5), @fecha, 110)
select @fecha = dateadd(dd, 1, @fecha)
end

drop table #horas
create table #horas (orden smallint identity, hora char(5))
declare @hora smalldatetime set @hora = '19000101 06:00'
while datepart(hh,@hora ) < 21
begin
insert #horas
select convert(char(5), @hora, 108)
select @hora = dateadd(mi, 30, @hora)
end

select fecha,
max(case when orden = 1 then hora end),
max(case when orden = 2 then hora end),
max(case when orden = 3 then hora end),
max(case when orden = 4 then hora end),
max(case when orden = 5 then hora end),
max(case when orden = 6 then hora end),
max(case when orden = 7 then hora end),
max(case when orden = 8 then hora end),
max(case when orden = 9 then hora end),
max(case when orden = 10 then hora end),
max(case when orden = 11 then hora end),
max(case when orden = 12 then hora end),
max(case when orden = 13 then hora end),
max(case when orden = 14 then hora end),
max(case when orden = 15 then hora end),
max(case when orden = 16 then hora end),
max(case when orden = 17 then hora end),
max(case when orden = 18 then hora end),
max(case when orden = 19 then hora end),
max(case when orden = 20 then hora end),
max(case when orden = 21 then hora end),
max(case when orden = 22 then hora end),
max(case when orden = 23 then hora end),
max(case when orden = 24 then hora end),
max(case when orden = 25 then hora end),
max(case when orden = 26 then hora end),
max(case when orden = 27 then hora end),
max(case when orden = 28 then hora end),
max(case when orden = 29 then hora end),
max(case when orden = 30 then hora end)
from #fechas
cross join #horas
group by fecha


"eider" escribió en el mensaje
news:
Hola a :
Tengo que hacer una consulta en sql server, en el cual lo que me
interesa es obetenr una tabla que tenga como columnas unas franjas
horarias (6-6:29, 6:30-6:59,7-7:290,) y como filas, todos los dias
del año (1 enero, 2 enero,.,1 julio, 2 julio,...). Podria alguien
decirme si hay forma de hacerlo???? Gracias por todo. Un saludo

Preguntas similares