Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Returning results from a SP
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00951236
Message ID:
00951239
Views:
8
--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.
>
>Here's the code of the SP
>
>
>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
>
>
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform