存储过程 变量 累加的问题
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