想在第二张桌子里获得价值 [英] want to get value in second table
问题描述
亲爱的所有创建以下过程sp_summary来获取表的总和和集合的结果到表余额中有列int expence,int collection,int balance但是在执行上面的过程之后我没有得到余额表中的值。请帮助
ALTER程序[dbo]。[sp_summary]
AS BEGIN
将@coll声明为int
将@exp声明为int
将@tot声明为int
选择@coll = SUM(金额)来自exnces
选择@exp = SUM(金额)来自收藏
选择@tot = @exp - @coll
插入余额
值(@ coll,@ exp,@ tot)
end
Dear All create following procedure sp_summary to get sum of tables expences and collection's result into table balance which have column int expence, int collection, int balance but after execute above procedure i don't get values in balance table. Kindly help
ALTER procedure [dbo].[sp_summary]
AS BEGIN
Declare @coll as int
Declare @exp as int
Declare @tot as int
select @coll = SUM(amount) from expences
select @exp = SUM(amount) from collection
select @tot = @exp - @coll
insert into balance
values (@coll,@exp,@tot)
end
推荐答案
插入余额(费用,收款) ,余额)
选择(从费用中选择总和(金额)),(从集合中选择SUM(金额)),(从集合中选择SUM(金额)) - (从费用中选择SUM(金额)) )
可以工作,不需要变量声明(等)......
看起来很漂亮虽然...
insert into balance (expense, collection, balance)
select (select sum(amount) from expenses), (select SUM(amount) from collection), (select SUM(amount) from collection) - (select SUM(amount) from expenses)
would work and doesn't need variables declaring (etc)...
looks naaaasty though...
如果你在ASP中这样做,而不是使用TSQL存储过程来插入值,那么将值更容易变为varb使用vb或其他任何语言编写文件,然后将存储过程创建为更简单的INSERT INTO语句,并将变量值作为参数传递。
if your doing it in ASP, then rather than using a TSQL stored procedure to insert the values, wouldn't it be easier to get the values as variables in vb or whatever your language, and then create your stored procedure as a much simpler INSERT INTO statement with the values of the variables passed as parameters.
这篇关于想在第二张桌子里获得价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!