我正在尝试填充来自的数据table1
to table2
,两者具有相同的列数。
中的所有列table1
属于类型varchar
。中的列table2
可能varchar
, int
or datetime
, etc.
我的问题是如何在填充过程中进行转换?
这是我编写的示例查询。我错过了进行转换的部分。还有我的格式datetime
is mm/dd/yyyy hh:mm:ss
.
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 t.notes_datetime =s.notes_datetime)
where t.acty_id is null
您将使用一个CAST() or CONVERT() https://learn.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-ver15在你的领域:
Declare @dt varchar(20)
set @dt = '08-12-2012 10:15:10'
select convert(datetime, @dt, 101)
对于您的查询,您将执行以下操作:
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)