sql >> Base de Datos >  >> RDS >> Sqlserver

¿Cómo convertir varchar a fecha y hora en T-SQL?

Utilizará un CAST() o CONVERT() en tu campo:

Declare @dt varchar(20)
set @dt = '08-12-2012 10:15:10'
select convert(datetime, @dt, 101)

Para su consulta haría lo siguiente:

insert into table2
select s.acty_id, s.notes_datetime, s.notes_data
from table1 t 
right join table2 s 
    on t.acty_id =s.acty_id 
    and convert(datetime, t.notes_datetime, 101) = s.notes_datetime
where t.acty_id is null