fjtello / SQL-C-sharp

Common programming and coding tips and howtos
0 stars 0 forks source link

SQL [#date #datepart #weekday] #42

Open fjtello opened 6 years ago

fjtello commented 6 years ago

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 /