如何在存储过程中的insert into语句的列值上加1?

问题描述 投票:0回答:1

我有一个每小时更新一次的表(RPT.SummaryAggregates)。我需要创建一个存储过程,每周用一次(RPT.SummaryAggregates)中的总记录快照填充表(RPT.WeeklyAggregates)(此SP将通过SQL Agent Job设置)。我需要(RPT.WeeklyAggregates)的“周”列在每次运行存储过程时自动递增1。该表中目前有一周的数据。

当前存储过程如下:

INSERT INTO RPT.WeeklyAggregates                      
SELECT 
    1 AS Week,                                                                                      
    SUM(BX),
    SUM(BK),
    SUM(MN),
    SUM(QN),
    SUM(SI),
    SUM(CF),
    (SUM(BX)+SUM(BK)+SUM(MN)+SUM(QN)+SUM(SI)+SUM(CF)) as Total                  
FROM RPT.SummaryAggregates

END;

表列是周,BX,BK,MN,QN,SI,CF,总计。

sql stored-procedures sql-insert auto-increment
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.