sql server - converting Year and Month varchar to date -


i have table month , year varchar. realized big mistake. since getting complicated query way.

 year month productname        2013  11      acb       2013  11      cde 

i add column called date , store these year month date existing table

   year  month   productname     date    2013   11        acb          2013-11-01    2013   11        cde          2013-11-01 

is there way can columns of existing table ??

please let me know

convert month , year columns strings concatenated '-'s , add '-01' end. convert date.

update t set t.[date] = convert(date, convert(varchar(4),                         t.[year]) + '-' + convert(varchar(2), t.[month]) + '-01') table t 

this create date records in table.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -