【发布时间】:2010-11-12 08:06:31
【问题描述】:
为简洁起见,我从临时表中省略了所有游标设置和 SELECT。基本上,此代码计算每个事务的所有事务的运行余额。
WHILE @@fetch_status = 0
BEGIN
set @balance = @balance+@amount
insert into @tblArTran values ( --from artran table
@artranid, @trandate, @type,
@checkNumber, @refNumber,@custid,
@amount, @taxAmount, @balance, @postedflag, @modifieddate )
FETCH NEXT FROM artranCursor into
@artranid, @trandate, @type, @checkNumber, @refNumber,
@amount, @taxAmount,@postedFlag,@custid, @modifieddate
END
受此代码的启发,来自另一个问题的答案,
SELECT @nvcConcatenated = @nvcConcatenated + C.CompanyName + ', '
FROM tblCompany C
WHERE C.CompanyID IN (1,2,3)
如果您明白我的意思,我想知道 SQL 是否能够以与连接字符串相同的方式对数字求和。也就是说,在不使用游标的情况下为每行创建一个“运行余额”。
有可能吗?
【问题讨论】:
标签: sql sql-server