ayuda con funciones
Publicado por renegado (26 intervenciones) el 10/12/2006 19:09:15
saludos , estoy creando esta fucnion ,
estoy nuevo en el tema, me podrian ayudar que es lo que tengo malo??
if exists(select * from sysobjects where name='WhenSuma' and type ='FN')
drop FUNCTION WhenSuma
go
create FUNCTION WhenSuma (@Codcuenta varchar,@mesAsumar int) RETURNS decimal (18,2)
AS
BEGIN
declare @saldos as decimal (18,2)
set @saldos = 0
declare tmpPlancuentas CURSOR FOR
select codcuenta,naturaleza,debito1,debito2,debito3,debito4,debito5,debito6,debito7,debito8,debito9
debito10,debito11,debito12,debito13,credito1,credito2,credito3,credito4,credito5,credito6,credito7,
credito8,credito9,credito10,credito11,credito12,credito13,debitoapertura,creditoApertura
from plancuentas
where codcuenta = @Codcuenta
open tmpPlancuentas
if (tmpPlancuentas.naturaleza = 'D')
set @saldos = tmpPlancuentas.debitoapertura - tmpPlancuentas.creditoApertura
else
begin
set @saldos = tmpPlancuentas.creditoApertura - tmpPlancuentas.debitoapertura
end
declare @Exprex1 as nvarchar(100),@ValDebito as decimal (18,2),@ValCredito as decimal(18,2),@Exprex2 as nvarchar(100)
declare @empezar int
set @empezar = 1
while (@empezar <= @mesAsumar)
begin
set @Exprex1 = 'debito'+ltrim(convert(char,@empezar))
set @ValDebito = @Exprex1
set @Exprex2 = 'credito'+ltrim(convert(char,@empezar))
set @ValCredito = @Exprex2
if (tmpPlancuentas.naturaleza = 'D')
set @saldos = @saldos + @ValDebito - @ValCredito
else
set @saldos = @saldos + @ValCredito - @ValDebito
set @empezar = @empezar + 1
end
return (@saldos)
estoy nuevo en el tema, me podrian ayudar que es lo que tengo malo??
if exists(select * from sysobjects where name='WhenSuma' and type ='FN')
drop FUNCTION WhenSuma
go
create FUNCTION WhenSuma (@Codcuenta varchar,@mesAsumar int) RETURNS decimal (18,2)
AS
BEGIN
declare @saldos as decimal (18,2)
set @saldos = 0
declare tmpPlancuentas CURSOR FOR
select codcuenta,naturaleza,debito1,debito2,debito3,debito4,debito5,debito6,debito7,debito8,debito9
debito10,debito11,debito12,debito13,credito1,credito2,credito3,credito4,credito5,credito6,credito7,
credito8,credito9,credito10,credito11,credito12,credito13,debitoapertura,creditoApertura
from plancuentas
where codcuenta = @Codcuenta
open tmpPlancuentas
if (tmpPlancuentas.naturaleza = 'D')
set @saldos = tmpPlancuentas.debitoapertura - tmpPlancuentas.creditoApertura
else
begin
set @saldos = tmpPlancuentas.creditoApertura - tmpPlancuentas.debitoapertura
end
declare @Exprex1 as nvarchar(100),@ValDebito as decimal (18,2),@ValCredito as decimal(18,2),@Exprex2 as nvarchar(100)
declare @empezar int
set @empezar = 1
while (@empezar <= @mesAsumar)
begin
set @Exprex1 = 'debito'+ltrim(convert(char,@empezar))
set @ValDebito = @Exprex1
set @Exprex2 = 'credito'+ltrim(convert(char,@empezar))
set @ValCredito = @Exprex2
if (tmpPlancuentas.naturaleza = 'D')
set @saldos = @saldos + @ValDebito - @ValCredito
else
set @saldos = @saldos + @ValCredito - @ValDebito
set @empezar = @empezar + 1
end
return (@saldos)
Valora esta pregunta


0