Q&A about the site for enthusiasts and power users of the Android operating system
create table #tbl (mon char(8) null,id int null, cnt int null); insert into #tbl (mon,cnt) values ('jul 2014',3100),('jan 2014',3200), ('may 2015',2300),('feb 2015',2600), ('aug 2014',1800),('mar 2015',3700), ('jun 2014',2400); update #tbl set id = datepart(month,cast(mon as datetime)) where id is null; select * from #tbl order by id; insert into #tbl (mon,cnt) values ('apr 2015',4500); update #tbl set id = datepart(month,cast(mon as datetime)) where id is null; select * from #tbl