Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Results Sets from Stored Procedures
Message
De
15/05/2007 17:34:57
Moacyr Zalcman
Independent Consultant
São Paulo, Brésil
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
01225649
Message ID:
01225802
Vues:
21
Hi, Sergey

I give just an example, but it is probably a bad one.
I will show you my real need:

I have this sproc
CREATE PROCEDURE dbo.usp_DDU
@ndias_calc int,@ldpontopartida datetime,@dataRetorno datetime
OUTPUT
AS
BEGIN
     
     if @ndias_calc=0
       BEGIN
            SET @dataRetorno=cast(convert(CHAR(11),@ldpontopartida,113) as datetime)
            RETURN 1
       END
       
     DECLARE @dtinicio datetime
     DECLARE @ndias Numeric(2,0)
     DECLARE @counter Numeric(2,0)
     DECLARE @diautil bit

     if @ndias_calc<0
        BEGIN
             SET @dtinicio=cast(convert(CHAR(11),@ldpontopartida,113) as datetime)-@ndias_calc-12
             SET @ndias=ABS(@ndias_calc)+12
        END
     else
       BEGIN
             SET @dtinicio=cast(convert(CHAR(11),@ldpontopartida,113) as datetime)
             SET @ndias=@ndias_calc+12
       END
        
        create table #DTodos(dia datetime, util bit)
        create table #DUtil(dia datetime,util bit)
        SET @counter=0
        while @counter<=@ndias
              BEGIN
                    insert into #DTodos values(@dtinicio+@counter,case when datepart(dw,@dtinicio+@counter) between 2 and 6 then 1 else 0 end)
                    SET @counter=@counter+1
              END
        update #Dtodos set util=0 where dia in (select dtferiado from feriado where dtferiado>=@dtinicio);

        if @ndias_calc>0
           BEGIN
                insert into #Dutil select dia,util from #DTodos where util=1 or dia=@dtinicio
                DECLARE @Teste Cursor
                select * from #DUtil where dia=@dtinicio
                if @@rowcount=0
                   SET @dataRetorno=@dtinicio
                else
                    BEGIN
                         DECLARE cr_dutil cursor local static for select * from #DUtil where dia>=@dtinicio
                         open cr_dutil
                         fetch first from cr_dutil into @dataRetorno,@diautil
                         if @diautil=0
                             set @ndias_calc=@ndias_calc+1
                         fetch relative @ndias_calc from cr_dutil into @dataRetorno,@diautil
                         close cr_dutil
                         deallocate cr_dutil
                    END
           END
        ELSE
            BEGIN
                set @dtinicio=cast(convert(CHAR(11),@ldpontopartida,113) as datetime)
                insert into #Dutil select dia,util from #DTodos where util=1 or dia=@dtinicio
                select * from #DUtil where dia=@dtinicio
                if @@rowcount=0
                   SET @dataRetorno=@dtinicio
                else
                    BEGIN
                         DECLARE cr_dutil cursor local static for select * from #DUtil where dia<=@dtinicio
                         open cr_dutil
                         fetch last from cr_dutil into @dataRetorno,@diautil
                         if @diautil=0
                             set @ndias_calc=@ndias_calc-1
                         fetch relative @ndias_calc from cr_dutil into @dataRetorno,@diautil
                         close cr_dutil
                         deallocate cr_dutil
                    END
           END
       drop table #Dtodos
       drop table #DUtil
       RETURN 1
END
This sproc receive two parameters, an inicial date and a number of days and I get the date after that inicial date plus that number of days excluding weekend and holidays( the holidays I have in a table called 'feriado') as an output parameter.
Everything works fine, but when I run these sproc I get the output parameter and also an cursor that was created with the [select * from #DUtil where dia=@dtinicio]. I don't need this cursor. Is there any way to avoid the delivery of this cursor to the client?

I hope you can now understand my need and thanks for your help.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform