SQL 插入月初

SQL insert first of month

我创建了一个初始 sql 插入到下面的 table 中。

spool_month spool_year  spool_month_part  spool_year_part   curr_cnt    prev_cnt    cal_prcnt_dff
July         2020         7               2020                21069199  NULL           0
September    2020         9               2020                18072707  21069199      14
October      2020        10               2020                17284440  18072707       4
November     2020        11               2020                17791289  17284440       3
December     2020        12               2020                20148679  17791289      13
January      2021         1               2021                22543049  20148679      12
February     2021         2               2021                24234982  22543049       8
March        2021         3               2021                26458351  24234982       9
April        2021         4               2021                 5946066  26458351      78

我可以创建一个仅在每月第一天将新数据插入此 table 的插入吗?因此,例如,在每个月的第一天插入前几个月的数据。

不知道从哪里开始这篇文章,所以任何反馈将不胜感激。

使用SqlAgent很容易解决这个问题;如果您只使用 SqlExpress,您将无法访问 SqlAgent,在这种情况下,您需要考虑使用 Windows Task Scheduler 和 Powershell,如果是这样的话 here is a useful guide

创建将执行插入的过程,并将其安排为每天 运行 从上面 link 的 SqlAgent 作业或 Powershell。

在您的程序中,将您的 insert 换成

if DatePart(day,GetDate())=1
begin

...

end