Hot answers tagged


DECLARE @t TABLE(InsertionDate datetime); INSERT @t(InsertionDate) VALUES(GETDATE()), ('20190125'); SELECT CONVERT(char(6), InsertionDate, 112) FROM @t; Result: 202004 201901


Not sure it is the best way but you could cast the date as a string and then use the "Right" to get only the month like so: declare @date datetime = getdate() select @date select MONTH(@date) select right(CONVERT(varchar(7),@date,102),2) If there is a lot of data, this will not be a performant way to do it. You could create a computed column that will ...


you can use generate_series() for that: insert into field (textfield, idcal) select '', c.idcal from calendar c where idcal = 42 cross join generate_series(1, c.numberoffields) as g(f)

Only top voted, non community-wiki answers of a minimum length are eligible