Sql 在#temp_表中选择null作为testdate

Sql 在#temp_表中选择null作为testdate,sql,sql-server,tsql,null,temp-tables,Sql,Sql Server,Tsql,Null,Temp Tables,是否有方法将日期时间值(getdate())插入/更新到按如下方式创建的临时表中: select id, null as testdate into #temp_table 然后是后来的声明: update #temp_table set testdate=getdate() 我得到一个错误: 无法将datetime转换为int 谢谢。将选择框中的列强制转换为 select id, cast(null as datetime) as testdate into #temp_table +

是否有方法将日期时间值(
getdate()
)插入/更新到按如下方式创建的临时表中:

select id, null as testdate
into #temp_table
然后是后来的声明:

update #temp_table 
set testdate=getdate()
我得到一个错误:

无法将datetime转换为int


谢谢。

将选择框中的列强制转换为

select id, cast(null as datetime) as testdate
into #temp_table

+1:没错。SQL Server中的NULL默认为INT;您需要将NULL强制转换为适当的数据类型,以便OP的内容正常工作。+1:我总是喜欢显式创建临时表的另一个例子。