使用存储过程在sql中添加多行 [英] adding Multiple rows in sql using stored procedure

查看:91
本文介绍了使用存储过程在sql中添加多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hii,如何使用存储过程在sql中添加多行.对于例如

假设a,b和c是3列,每列3个值
a b c
1 4 7
2 5 8
3 6 9

现在我想从a,b和c中添加1 + 4 + 7..

hii, how do v add multiple rows in sql using stored procedure. for eg

suppose a,b and c are 3 columns with 3 values each
a b c
1 4 7
2 5 8
3 6 9

now I want to add 1+4+7 from a,b and c..

推荐答案

您是否尝试过?

Have you tried this?

SELECT ISNULL(a,0) + ISNULL(b,0) + ISNULL(c,0) AS 'TotalPerColumn' FROM [tablename]



其中a,b,c是您的列名.结果将是:



wherein a,b,c are your column names. The result would be:

TotalPerColumn
--------------
12
15
18


如果这解决了您的问题,请标记为答案并投票5

问候,
爱德华(Eduard)


Please mark as answer and vote 5 if this solved your problem

Regards,
Eduard


CREATE PROCEDURE usp_ 
( @S int output ) 
AS 
set @S= (SELECT SUM(Ke) AS 'Column1_SUM' FROM [test])


CREATE PROCEDURE usp_ 
( @S int output ) 
AS 
set @S= (SELECT SUM(Ka) AS 'Column2_SUM' FROM [test])


CREATE PROCEDURE usp_ 
( @S int output ) 
AS 
set @S= (SELECT SUM(Ta) AS 'Column3_SUM' FROM [test])



这些将显示每列的总和.您可以创建一个动态的storageproc而不是此动态的.

问候,
爱德华



these will display the sum of each columns. You can create one dynamic storedproc instead of this one.

Regards,
Eduard


这篇关于使用存储过程在sql中添加多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆