我的存储过程有两个游标。 存储过程的输出格式如下。存储过程输出错误
companyid companyname id idname level3 level4 level5 currency accountdefinition accname accountno debits credits
----------- -------------------------------------------------- ----------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ----------- --------------------------------------- ---------------------------------------
101 Fund One Company 1001 Test Fund Assets Assets for PL Accounts NULL NULL NULL NULL NULL KWD CA Current Account NULL NULL NULL
(1 row(s) affected)
companyid companyname id idname level3 level4 level5 currency accountdefinition accname accountno debits credits
----------- -------------------------------------------------- ----------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ----------- --------------------------------------- ---------------------------------------
101 Fund One Company 1001 Test Fund Assets Assets for PL Accounts NULL NULL NULL NULL NULL KWD CA Current Account NULL NULL NULL
(1 row(s) affected)
companyid companyname id idname level3 level4 level5 currency accountdefinition accname accountno debits credits
----------- -------------------------------------------------- ----------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ----------- --------------------------------------- ---------------------------------------
101 Fund One Company 1001 Test Fund Assets Accounts for MM PL accounts NULL NULL NULL NULL NULL KWD MPL PL accounts for MM NULL NULL NULL
(1 row(s) affected)
而不是将所有3行显示为单个输出。它将每行显示为单个输出。这在报告级别造成问题。
代码:
alter PROCEDURE TrialBalance
(
@companyid INT,
@id INT --Input parameter , Studentid of the student
[email protected] VARCHAR(200) OUT -- Out parameter declared with the help of OUT keyword
)
AS
BEGIN
declare @level3 varchar(50),@level4 varchar(50),@level5 varchar(50),@level6 varchar(50),@level7 varchar(50),@level8 varchar(50),@level9 varchar(50),@level10 varchar(50),@level11 varchar(50),@rfrom int,@rto int,
@companyname varchar(50),@idname varchar(50),@accname varchar(50),@debits decimal(15,3),@credits decimal(15,3),@acno int,@acname varchar(25)
declare c cursor for SELECT
level3,
level4,
level5,
level6,
level7,
level8,
level9,
level10,
level11,
rangefrom,
rangeto
from linedetails where level1 = @companyid and level2 = @id order by reportlineid
select @companyname = description from company where companycode = @companyid
select @idname = description from fundparameters where fundid = @id
open c
fetch next from c into @level3,@level4,@level5,@level6,@level7,@level8,@level9,@level10,@level11,@rfrom,@rto
WHILE @@FETCH_STATUS = 0
BEGIN
select @accname = description from accounttype where accounttypeid = @level11
if @rfrom is not null and @rto is not null
declare d cursor for select accountno,totaldebitslcy,totalcreditslcy from fund.dbo.account where (accountno >= @rfrom and accountno <= @rto) and currency = @level10
open d
fetch next from d into @acno,@debits,@credits
WHILE @@FETCH_STATUS = 0
BEGIN
select @companyid as companyid ,@companyname as companyname ,@id as id ,@idname as idname,@level3 as level3 ,@level4 as level4,@level5 as level5,
@level6,
@level7,
@level8,
@level9,
@level10 as currency,
@level11 as accountdefinition ,@accname as accname,@acno as accountno, @debits as debits,@credits as credits
fetch next from d into @acno,@debits,@credits
end
close d
deallocate d
fetch next from c into @level3,@level4,@level5,@level6,@level7,@level8,@level9,@level10,@level11,@rfrom,@rto
end
end
close c
deallocate c
我认为你在做光标循环内的输出?这可能可以解释... – 2013-05-07 13:02:49
是的,这是一个问题吗?否则如何去做? – Nelsons 2013-05-07 13:04:02
显示程序,我的魔法8球显示我的机器今天早上坏了。 – 2013-05-07 13:04:11