
14/03/2007, 13:45
|
| | Fecha de Ingreso: enero-2004 Ubicación: Colombia
Mensajes: 80
Antigüedad: 21 años, 1 mes Puntos: 0 | |
Vista Declarando variables Saludos.
Les tengo la siguiente consulta, agardezco cualquier información al respecto.
Trabajo sobre MS SQLSERVER 2000 y estoy tirando una consulta declarando variables por el analizador de consultas y corre sin ningun problema. Ahora necesito dejar este script como una vista (view) ¿Es posible?.
Adjunto el script
Código:
Declare @fecha03 datetime
Declare @fecha36 datetime
Declare @fecha612 datetime
Declare @fecha12 datetime
Set @fecha03=convert(datetime,DATEADD(month,-3, getdate()),105)
Set @fecha36=convert(datetime,DATEADD(month,-3, @fecha03 ),105)
Set @fecha612=convert(datetime,DATEADD(month,-6, @fecha36),105)
Set @fecha12=convert(datetime,DATEADD(month,-12, @fecha612),105)
select "Costo Inmobilizados 0-3 meses"=sum(costo)
from v_inmobilizados
where fuv between @fecha03 and getdate()
group by ano, mes
UNION ALL
select "Costo Inmobilizados 3-6 meses"=sum(costo)
from v_inmobilizados
where fuv between @fecha36 and @fecha03
group by ano, mes
UNION ALL
select "Costo Inmobilizados 6-12 meses"=sum(costo)
from v_inmobilizados
where fuv between @fecha612 and @fecha36
group by ano, mes
UNION ALL
select "Costo Inmobilizados Mas 12 meses"=sum(costo)
from v_inmobilizados
where fuv between '01-06-1998' and @fecha612
and fuc between '01-06-1998' and @fecha612
group by ano, mes
como puedo hacerlo??
Gracias nuevamente |