sql-server - 复制过去月份的数据
问题描述
我有一张表格,每天都会在其中捕获数据。例如:列是帐户、资金编号、金额、日期。假设数据被捕获到 2020 年 12 月 31 日,下一个数据从 2021 年 3 月 1 日开始。现在,我的要求是我想从上次输入的数据(即 12 月 31 日)中填充 2021 年 1 月 1 日至 2021 年 2 月 28 日的数据, 2020.我想复制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
推荐阅读
- python - 从python评估“带有shell变量的Shell命令行”或将python字符串评估为shell命令行
- .net - 有没有办法创建一个无控制台的 dotnet 核心应用程序?
- c# - 等待从数据库加载数据时调用 Workbook_SheetChange()
- javascript - 只能调用一次的函数
- css - 将图像和文本与 flex 容器项中的类对齐
- c# - 在 C# 中工作的正则表达式在 MSBuild 中不起作用
- reactjs - 在 Gatsby-React 类组件中使用 Graphql 获取数据
- java - ZonedDateTime序列化差异与不同服务器上相同的代码和相同的依赖关系
- php - 在使用 jquery 隐藏模式后,我必须单击两次才能打开模式
- python - 我有这个 while 循环:while x == False 或 y != 10: ,但是当 Y 变为 10 时,它会继续运行循环