Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 将当前日期值插入列_Sql_Sql Server_Date_Sql Insert - Fatal编程技术网

Sql 将当前日期值插入列

Sql 将当前日期值插入列,sql,sql-server,date,sql-insert,Sql,Sql Server,Date,Sql Insert,能否通过带有insert语句的函数插入当前日期 应该是这样的: insert into table name values (getdate(), getdate()-1) ,(getdate(), getdate()-1) 上面的例子可能很模糊,但这个概念可以做到吗?一句话-是的。您可以使用函数调用或计算的结果作为insert语句的values子句的参数。是的,您可以直接操作函数 SELECT GETDATE()-1 但我将使用DATEADD函数 难道你不能自己检查一下吗?@Giorgi

能否通过带有insert语句的函数插入当前日期

应该是这样的:

insert into table name 
values
(getdate(), getdate()-1)
,(getdate(), getdate()-1)

上面的例子可能很模糊,但这个概念可以做到吗?

一句话-是的。您可以使用函数调用或计算的结果作为insert语句的values子句的参数。

是的,您可以直接操作函数

SELECT GETDATE()-1
但我将使用DATEADD函数


难道你不能自己检查一下吗?@Giorgi Nakeuri..你不知道有些人会一直在研究这种情况,无法立即进入一个系统并思考它theoretically@JaydipJ,它看起来像是Microsoft Sql Server谢谢,所以它会像选择getdate,选择getdate-1ty。。从理论上讲,使用date add(日期添加)而不是直接操作date add(日期添加)函数会有什么不同?date add函数内部管理需要添加的内容,无论是DAY->D,YEAR->Y还是etcone。有趣的是,如果您尝试选择sysdatetime-1,则会出现错误
SELECT DATEADD(D,-1,GETDATE())