declare @fechaInicial as date = getdate();
declare @numeroFechas as int = 10;
declare @ff as int = 0;
declare @t as table (id int identity(1,1), fecha date, wd varchar(1) null);
while (@ff < @numeroFechas)
begin
insert into @t (fecha) values (dateadd(d, -@ff, @fechaInicial));
set @ff = @ff + 1;
end
update @t set wd = (case datepart(weekday, fecha) when 1 then 'D' when 2 then 'L' when 3 then 'M' when 4 then 'X' when 5 then 'J' when 6 then 'V' when 7 then 'S' else '' end);
select id, fecha, wd from @t;
/
DatePart(weekday, date)
1 - 2 - 3 - 4 - 5 - 6 - 7
D - L - M - X - J - V - S
/
declare @fechaInicial as date = getdate(); declare @numeroFechas as int = 10; declare @ff as int = 0; declare @t as table (id int identity(1,1), fecha date, wd varchar(1) null); while (@ff < @numeroFechas) begin insert into @t (fecha) values (dateadd(d, -@ff, @fechaInicial)); set @ff = @ff + 1; end update @t set wd = (case datepart(weekday, fecha) when 1 then 'D' when 2 then 'L' when 3 then 'M' when 4 then 'X' when 5 then 'J' when 6 then 'V' when 7 then 'S' else '' end); select id, fecha, wd from @t; / DatePart(weekday, date) 1 - 2 - 3 - 4 - 5 - 6 - 7 D - L - M - X - J - V - S /