Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.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 server 从后续月份复制数据_Sql Server - Fatal编程技术网

Sql server 从后续月份复制数据

Sql server 从后续月份复制数据,sql-server,Sql Server,我有一个表,其中每天都会捕获数据。 例如:列是account、fundnumber、amount、date。 假设数据在2020年12月31日之前被捕获,下一个数据从2021年3月1日开始出现。 现在,我的要求是,我要根据上次输入的数据(即2020年12月31日)填写2021年1月1日至2021年2月28日的数据。 我想复制2020年12月31日的数据,并填写2021年1月1日至2月28日 可能吗? 请告诉我解决方案。您可以通过运行while循环来完成 DECLARE @currentDate

我有一个表,其中每天都会捕获数据。 例如:列是account、fundnumber、amount、date。 假设数据在2020年12月31日之前被捕获,下一个数据从2021年3月1日开始出现。 现在,我的要求是,我要根据上次输入的数据(即2020年12月31日)填写2021年1月1日至2021年2月28日的数据。 我想复制2020年12月31日的数据,并填写2021年1月1日至2月28日

可能吗?
请告诉我解决方案。

您可以通过运行while循环来完成

DECLARE @currentDate Date;
set @currentDate = '2021-01-01'
WHILE @currentDate <= '2021-02-28' 
BEGIN
    insert into yourtable(account, fundnumber, amount, date) select account, fundnumber, amount, @currentDate from yourtable where date='2020-12-31'
    SET @currentDate = DATEADD(day, 1, @currentDate)
END
DECLARE@currentDate;
设置@currentDate='2021-01-01'

而@currentDate感谢您的回复。我们是否可以编写select查询,将跟踪数据复制到所述日期(2021年1月1日至2021年2月28日),然后一次性获得所有详细信息?