Solved

Clear OUTPUT buffer in stored procedure

Posted on 2004-09-03
10
480 Views
Last Modified: 2008-02-01
Hello,

I have stored procedures which call other stored procedures for the purpose of reduced points of maintenance. The issue is all the sub stored procedures in the main one also return resultsets. I want to ignore these in my main SP and retrun a single resultselt at the end, which is an error code.

Is it possible to clear the pending resultsets at the end of a storedprocedure? I found how to access the OUTPUT buffer, however there doesn't seem to be a way of clearing it. Has anyone tried this, or got any ideas for how to overcome this?

Thanks,

Mike
0
Comment
Question by:beelineuk
  • 4
  • 4
  • 2
10 Comments
 
LVL 18

Expert Comment

by:ShogunWade
ID: 11974428
Perhaps you could explain a bit more.    I dont understand why you are returning resultsets from your stored procs if you dont want them
0
 
LVL 2

Author Comment

by:beelineuk
ID: 11974536
Because these stored procedures can be used independently and also return result codes to the client as required. When used within the main SP this handles the errors seperately and should just return the final result.  
0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 11974763
I think ultimately that you ned to rethink the design a bit.  a stored proc should only return what is required of it.    
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 2

Author Comment

by:beelineuk
ID: 11974893
true, but I'm gaining single point of maintainence, and by solving this problem I will be doing exactly that. Anyway I've now found quite a neat solution.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 11975066
How about stuffing that outputs into (local) temp tables?

Example:

create table #one (a varchar(20));
insert into #one exec usp_example;
...
0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 11975069
Kinda off the question a bit,  but there is often big discussions about whether stored procs should be reused or not.   Im of the opinion that in most cases it is better not to reuse.... why ?   mainly because of the amount of times ive seen disasterous results where someone changes a common stored proc without realizing the knock on effects.

But its one of those subjects where there will never be a consensus ;S

0
 
LVL 2

Author Comment

by:beelineuk
ID: 11975085
That was my orginaly get out trick, however you cannot have transactions within the sprocs when you do this, so it didn't work.
0
 
LVL 18

Accepted Solution

by:
ShogunWade earned 500 total points
ID: 11975172
" cannot have  transactions within the sprocs when you do this, so it didn't work."

Ah i can help you there.



@ the start of your procs   check @@NESTLEVEL    this will tell you how deep you are in the "Callstack"  thus if

SET @n=@@NESTLEVEL
IF @n=0
  BEGIN TRAN trnname
ELSE
  CHECKPOINT TRAN trnname


then @ end of proc

IF @n=0
   COMMIT TRAN



thus ising only 1 transaction but checkpointing the transaction at key stages to allow intermediate rollback.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 11975218
I aggree
0
 
LVL 2

Author Comment

by:beelineuk
ID: 11995068
Well it's not far off my solution I also used @@Nestlevel, however I used this to disable the select in the sub stored procedures, rather than the example above which still requires the use of temporary tables.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question