Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/12/2011, 23:47
yoniti7784
 
Fecha de Ingreso: mayo-2011
Ubicación: sinaloa
Mensajes: 150
Antigüedad: 13 años, 6 meses
Puntos: 4
Pregunta Inserccion desconocida.

Buen dia. Alguien me pude ayudar a desifrar lo que significa este codigo::
en realidad lo que no entiendo es lo que esta en negrita.

DECLARE @fDesde DATETIME, @fHasta DATETIME
SELECT @fDesde = '20010101', @fhasta = '20111205'
;WITH
l0 AS(SELECT 0 AS c UNION ALL SELECT 0),
l1 AS(SELECT 0 AS c FROM l0 AS a, l0 AS b),
l2 AS(SELECT 0 AS c FROM l1 AS a, l1 AS b),
l3 AS(SELECT 0 AS c FROM l2 AS a, l2 AS b),
l4 AS(SELECT 0 AS c FROM l3 AS a, l3 AS b),
l5 AS(SELECT 0 AS c FROM l4 AS a, l4 AS b),
l6 AS(SELECT 0 AS c FROM l5 AS a, l5 AS b),
nums AS(SELECT ROW_NUMBER() OVER(ORDER BY c) AS n FROM l6)

INSERT table_1 (nombre,anio,mes,dia,numdia,semana,quarter,bimestr e,trimestre,semestre)
SELECT
DATEADD(DAY, nums.n - 1, @fDesde),
YEAR(@fDesde+nums.n - 1),
MONTH(@fDesde+nums.n - 1),
Day(@fDesde+nums.n - 1),
Datepart(dayofyear,@fDesde+nums.n - 1),
Datepart(weekday,@fDesde+nums.n - 1),
Datepart(quarter,@fDesde+nums.n - 1),
case
when month(@fDesde+nums.n - 1) in (1,2) then 1
when month(@fDesde+nums.n - 1) in (3,4) then 2
when month(@fDesde+nums.n - 1) in (5,6) then 3
when month(@fDesde+nums.n - 1) in (7,8) then 4
when month(@fDesde+nums.n - 1) in (9,10) then 5
when month(@fDesde+nums.n - 1) in (11,12) then 6
end,
case
when month(@fDesde+nums.n - 1) in (1,2,3) then 1
when month(@fDesde+nums.n - 1) in (4,5,6) then 2
when month(@fDesde+nums.n - 1) in (7,8,9) then 3
when month(@fDesde+nums.n - 1) in (10,11,12) then 4
end,
case
when month(@fDesde+nums.n - 1) in (1,2,3,4,5,6) then 1
when month(@fDesde+nums.n - 1) in (7,8,9,10,11,12) then 2
end
FROM nums WHERE n <= DATEDIFF(DAY, @fDesde, @fHasta) + 1