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日 可能吗?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
请告诉我解决方案。您可以通过运行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日),然后一次性获得所有详细信息?