以文本方式查看主题

-  易表在线答疑  (http://egrid2000.com/dvbbs/index.asp)
--  用户社区  (http://egrid2000.com/dvbbs/list.asp?boardid=2)
----  sql存储过程的问题  (http://egrid2000.com/dvbbs/dispbbs.asp?boardid=2&id=3035)

--  作者:happyli
--  发布时间:2010/12/14 20:48:00
--  sql存储过程的问题
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)赋值每次都只能取到一个值。。如何才能循环的取出多个值呢???


--  作者:程兴刚
--  发布时间:2010/12/15 1:36:00
--  
到这里提问试试:

       http://www.foxtable.com