2

This may be a dumb question, I have tried googling but I am probably not phrasing this properly so I will try to explain the problem here:

I am using SQL Server 2000 and I have a stored procedure (SP1) that iterates through a table with 3 records and executes another stored procedure (SP2) at each iteration.

SP2 does an insert and then does a select on the inserted record.

SP1 continues after the iterating, it does one select then ends.

When I execute SP1 I only want the resultset from that last select returned. But with this iteration I am getting 4 resultsets (1 for each of the iterations and then the SP1 select at the end) all returned.

Is there some way to say don't return the resultset of SP2 when I am iterating them as part of SP1?

I could create another stored procedure that is exactly the same as SP2 but which does not have a select at the end, that would probably handle it. But I would prefer to add something to SP1 which prevents the resultset from returning. Is that possible?

Here's what the iteration in SP1 looks like right now:

set nocount on
declare c cursor for select room_id from st_room_ref where active = 1
declare @room_id int,
        @max_c int

open c

while 1 = 1
begin
    fetch c into @room_id
    if @@fetch_status <> 0 break

    select  @max_c = max(call_id) 
    from    st_call 
    where   room_id = @room_id 

    if      @max_c is null
    exec    st_getCall @room_id
end

close c
deallocate c

Please no dissertations on the wrongness of cursors. Just was hoping for some way to tell the st_getCall SP not to send it's result set back.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
egerardus
  • 11,316
  • 12
  • 80
  • 123

1 Answers1

1

Have you tried the following?

INSERT INTO
  @itteration_results
EXEC
  st_getCall @room_id

There is a restriction with this; you can't nest it any deeper; st_getCall can't have the same inside it.

If you do end up needing that, you may get more milage from the accepted answer to this question:

Community
  • 1
  • 1
MatBailie
  • 83,401
  • 18
  • 103
  • 137