set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author:<Author,,Name>
-- Create date: <Create Date,,>
-- Description:<Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[view_wuzhi]
@dwid int
-- Add the parameters for the stored procedure here
as
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @input int;
declare @output int;
select @input=sum(dNum) from dbo.View_wuzi where datediff(mm,dTime,getdate())=1 and DWID=@dwid and dType=0 group by DCID
select @output=sum(dNum) from dbo.View_wuzi where datediff(mm,dTime,getdate())=1 and DWID=@dwid and dType=1 group by DCID
select cName,cGe,uName,@input-@output from View_wuzi where DCID in(select distinct DCID from dbo.View_wuzi where DWID=@dwid) group by cName,cGe,uName
END
在这个存储过程中。。这个sum(dNum)查询出来是有多条数据,然后 @input=sum(dNum)赋值每次都只能取到一个值。。如何才能循环的取出多个值呢???