sql - 选择 null 作为 testdate 进入 #temp_table

标签 sql sql-server tsql null temp-tables

有没有办法将日期时间值(getdate())插入/更新到如下创建的临时表中:

select id, null as testdate
into #temp_table

然后是稍后的声明:

update #temp_table 
set testdate=getdate()

我收到错误:

cannot convert datetime into int...

谢谢。

最佳答案

将选择中的列转换到

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

关于sql - 选择 null 作为 testdate 进入 #temp_table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3711626/

相关文章:

Mysql嵌套循环中最外层表可见性

php - SQL 语句基于 $curr_time->format ('Y-m-d H:i' )

sql - 此检查是否可以避免 SQL 注入(inject)?

c# - 通过传递逗号分隔值删除记录 SQL Server 和 C#

sql - 如何终止或回滚事件事务?

sql-server - 当文档似乎说它不会时,在表上使用 sp_rename 会更新表的外键

php - 一次执行多个 SQL 查询

php - SQLSTATE[42000] : Syntax error or access violation: 1064 PHP/MySQL

sql - varchar 的透视列

sql-server - 出现错误时退出并回滚脚本中的所有内容