--Return Select * From Datos Select * From @Datos>Hello everybody, I've made a SP in SQL2K,the SP is working fine but I need to know how to return the resulting records to the calling program. By default I'm getting the last record fetched from the cursor named curcerti. I'm using ADO to call the store procedure from VFP.
>CREATE PROCEDURE P_ESTADOCTAGEN (@FechaFin As Datetime) AS >Declare @CertNum Int >Declare @Inversionista Int >Declare @Nombre nVarchar(40) >Declare @Descripcion nVarchar(20) >Declare @InteresAnual Money >Declare @ValorInicial Money >Declare @Tipo Int >Declare @InteresPagado Money >Declare @InteresAcumulado Money >Declare @Balance Money >Declare @InteresDelMes Money >Declare @Capital Money >Declare @Dias Int >Declare @FechaIni DateTime > >Declare @Datos Table(Certificado Int,Inversionista nVarChar(40), >Descripcion nVarChar(20),Valor Money,Tasa Money,IntAcum Money, >IntPagados Money,IntMes Money,Balance Money) > >--Cursor inicial con los certificados >Declare curCerti Cursor FOR >Select Certificados.Certificado,Certificados.Inversionista,Inversionistas.Nombre, >Certificados.Tipo,TipoInversiones.Descripcion,Certificados.ValorInicial,Certificados.InteresAnual >From Certificados >Left outer Join TipoInversiones On Tipoinversiones.Tipo=Certificados.Tipo >Left Outer Join Inversionistas On Inversionistas.Inversionista=Certificados.Inversionista > >-- Abro el cursor >OPEN CurCerti > >-- Inicio ciclo para leer los datos del cursor >FETCH NEXT FROM CurCerti > > > WHILE @@FETCH_STATUS = 0 > BEGIN > FETCH NEXT FROM curCerti > Into @CertNum, > @Inversionista, > @Nombre, > @Tipo, > @Descripcion, > @ValorInicial, > @InteresAnual > > Set @InteresPagado = Isnull((Select Sum(Interes) AS Interes From IvmMovi > Where Interes>0 And Tipo in (Select Tipo From TipoMovIvm Where Suma=0 And Interes=1) > And IvmMovi.Fecha<=@FechaFin And IvmMovi.Certificado=@CertNum),0) > > Set @InteresAcumulado = IsNull((Select Sum(Interes) AS Interes From IvmMovi > Where Interes>0 And Tipo in (Select Tipo From TipoMovIvm Where Suma=1 And Interes=1) > And IvmMovi.Fecha<=@FechaFin And IvmMovi.Certificado=@CertNum),0) > > --- Seteo las demas variables para calcular el interes del mes > Set @FechaIni = (Select IsNull(FechaInteres,FechaInicio) From Certificados Where Certificado=@CertNum) > Set @Dias = (SELECT dbo.FN_DIASACALCULAR (@FechaIni,@FechaFin)) > > If @Tipo=1 --Si es Normal > Begin > Set @Capital=@ValorInicial > End > Else > Set @Capital=(@ValorInicial+@InteresAcumulado)-@InteresPagado > > > Set @InteresDelMes= (SELECT DBO.FN_INTERESDIARIO (@Capital,@InteresAnual) * @Dias) > > > Set @Balance= (@ValorInicial+@InteresAcumulado+@InteresDelMes)-@InteresPagado > Insert @Datos Values(@CertNum,@Nombre,@Descripcion, > @ValorInicial,@InteresAnual,@InteresAcumulado,@InteresPagado,@InteresDelMes,@Balance) > > END > >CLOSE curCerti -- Cierro el cursor >DEALLOCATE curCerti -- Libero la memoria utilizada por el cursor > >Return Select * From Datos >GO > >>