0

我遇到了一个疯狂的问题.iam 在 XL 表中手动执行是否有机会在存储过程中执行。

我创建了一个用于插入数据的存储过程

CREATE PROCEDURE Dataloading
AS
BEGIN
    truncate table TABLE1

    insert TABLE1 (
        [Name],
        [Share]
    )
    select 
        [Name], 
        sum(Share)
    from TABLE2
    group by [Share]

END


Output is 

texas     3000 

dallas    5000

ca        5000

sfo       7000

newyork   8000

alaska    4000

我需要将输出输入到 TABLE1 中,因为添加除阿拉斯加以外的所有份额并减去 alska 并在下面的行中打印。

I want output look like :-
texas     3000 

dallas    5000

ca        5000

sfo       7000

newyork   8000

G total  28000

alaska    4000

Total    24000

你能看看这个吗?

4

1 回答 1

1

您可以尝试连续插入:

CREATE PROCEDURE Dataloading
AS
BEGIN
truncate table TABLE1

insert TABLE1 (
    [Name],
    [Share]
)
select 
    [Name], 
    sum(Share)
from TABLE2
 where [Name] not like '%alaska%'
group by [Share]

insert TABLE1 (
    [Name],
    [Share]
)
select 'G total', sum([Share]) from TABLE1 

insert TABLE1 (
    [Name],
    [Share]
)
select 
    [Name], 
    sum(Share)
from TABLE2
 where [Name] like '%alaska%'
group by [Share]

insert TABLE1 (
    [Name],
    [Share]
)
select 'Total', sum([Share]) from TABLE1 

END

希望它有点帮助:)

您还可以添加一些疯狂的排序列。可能你会需要它

于 2013-09-10T18:15:07.767 回答