首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

存储过程 变量 累加的有关问题

2012-01-21 
存储过程 变量 累加的问题ALTERPROCEDURE[dbo].[Proc_Test](@Timedatetime,@SUMValuedecimaloutput)ASBEGI

存储过程 变量 累加的问题
ALTER   PROCEDURE   [dbo].[Proc_Test]
(
@Time   datetime,
@SUMValue   decimal   output
)
AS

BEGIN
SET   NOCOUNT   ON;
        DECLARE   @ReturnValue   decimal
DECLARE   MyCursor   CURSOR   FOR   SELECT   YUEZONGJ   FROM   v_Syn_BIZ_MSP_LISTMS   Where   MEASDATE   <   @Time
DECLARE   @T_T   decimal
        OPEN   MyCursor
FETCH   NEXT   FROM   MyCursor   into   @T_T
WHILE   @@FETCH_STATUS   =   0
      BEGIN
    set   @ReturnValue   =+round(N '12 '*isnull(@T_T,0),0)

            FETCH   NEXT   FROM   MyCursor;
      END

CLOSE   MyCursor
DEALLOCATE   MyCursor
END

以上为存储过程:请问这个能实现   set   @ReturnValue   =+round(N '12 '*isnull(@T_T,0),0)
的累加吗?我最后要返回@ReturnValue   的数值。


[解决办法]
在定义游标前给@ReturnValue赋0
循环内
set @ReturnValue =@ReturnValue+round(N '12 '*isnull(@T_T,0),0)
[解决办法]
ALTER PROCEDURE [dbo].[Proc_Test]
(
@Time datetime,
@SUMValue decimal output
)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @ReturnValue decimal
select @ReturnValue = sum(round(12*isnull(YUEZONGJ,0))) from v_Syn_BIZ_MSP_LISTMS Where MEASDATE < @Time
END
[解决办法]
ALTER PROCEDURE [dbo].[Proc_Test]
(
@Time datetime,
@SUMValue decimal(10,2) output
)
AS

BEGIN
SET NOCOUNT ON;
DECLARE @ReturnValue decimal(10,2)
set @ReturnValue=0.00
DECLARE MyCursor CURSOR FOR SELECT YUEZONGJ FROM v_Syn_BIZ_MSP_LISTMS Where MEASDATE < @Time
DECLARE @T_T decimal
OPEN MyCursor
FETCH NEXT FROM MyCursor into @T_T
WHILE @@FETCH_STATUS = 0
BEGIN
set @ReturnValue =@ReturnValue+round(N '12 '*isnull(@T_T,0),0)
FETCH NEXT FROM MyCursor into @T_T /*加上into @T_T*/
END

CLOSE MyCursor
DEALLOCATE MyCursor
set @SUMValue = @ReturnValue /*将累加的值赋予输出型参数*/
END

热点排行