sql server - Convert and Insert varchar date from one table to another -


i want insert date 1 table another. problem is, source table having date stored varchar , destination date datatype.

also want change format of date while inserting destination.

table1 date varchar(80) null  table2 date date null 

date in table1 stored in mm-dd-yyyy want convert dd.mm.yyy , store table2.

how should convert it? tried below, not working.

select convert(varchar(10),try_convert(date,[date]),104) 

if destination table has date field of date type should convert source data date type , insert it.

the format dd.mm.yyyy want output not date format string , can date data second table using convert string format 104 while selecting data second table this:

declare @table1 table ([date] varchar(80) null); insert @table1 values ('12-31-2001'), ('02-28-2002');  declare @table2 table ([date] date null);  insert @table2 select convert(date, [date], 101) @table1;  select convert(char(10), [date], 104) @table2; 

here used table variables , should use table1, table2 instead


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -