Ver Mensaje Individual
  #3 (permalink)  
Antiguo 27/09/2010, 15:59
chimaria
 
Fecha de Ingreso: marzo-2009
Mensajes: 121
Antigüedad: 15 años
Puntos: 1
Respuesta: Seleccion de datepart

Cita:
Iniciado por flaviovich Ver Mensaje
Prueba asi:
Código SQL:
Ver original
  1. DECLARE @i SMALLINT
  2. DECLARE @fecha datetime
  3. DECLARE @anios TABLE( anio SMALLINT )
  4.  
  5. SET @fecha = '19500101'
  6. SET @i = YEAR(@fecha)
  7.  
  8. while @i <= YEAR(getdate())
  9. BEGIN
  10.     INSERT INTO @anios VALUES(@i)
  11.     SET @i = @i + 1
  12. END
  13.  
  14. SELECT * FROM @anios ORDER BY anio DESC




Gracias de verdad te lo agradezco si me funciono