I want to add the last 12 months to a SQL Server table, something like the following:
FixedText Jan-14 Feb-14 Mar-14 Apr-14 May-14 Jun-14 Jul-14 Aug-14 Sep-14 Oct-14 Nov-14 Dec-14 Jan-15
Please can someone help with with this?
Thanks
EDIT: Table schema is as follows:
Department Month12 Month11 Month10 Month9 Month8 Month7 Month6 Month5 Month4 Month3 Month2 Month1
----------- --------- --------- --------- -------- -------- -------- -------- -------- -------- -------- -------- -------
Best Answer
Perhaps you want something like this?
This assumes several things.
DATE
(or perhapsDATETIME
, etc) as the data type for the 12 columns for each month.2014-01-02
,2014-02-02
, ...2014-12-02
into the table.If you are using SQL Server 2012 and above, you can modify this:
to this:
To get the date as Jan-2014. There are also a lot of other ways that are probably more efficient.