Advertisement

12.01.2005 at 01:52PM PST, ID: 21650043
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Multiple Output Parameters from SELECT in Stored Procedure

Asked by MarkNethercott in MS SQL Server

Tags: , , , ,

I have a nested set of SELECT statements that (eventualy) returns two aggregate functions (SUM) - SUM(CpuLoad) & SUM(MemLoadKybytes)

There are a variety of parameters passed to the select statement, so I have built up the final command from a number of varchars.

I'd like to know how to get the two answers in to two output parameters (@sCPULoad & @sMemLoadKbytes).

THe full stored proceudre is below, but in general terms the statements is as follows;

SET @queryText3 = 'SELECT @sCPULoad=sCL, @sMemLoadKbytes=sML FROM (SELECT SUM(CpuLoad) AS sCL, SUM(MemLoadKbytes) AS sML FROM (SELECT ASProcessID, max(StatsTime)...<remaining SELECT statement>)

And I'm calling it as

EXEC @queryText3 @sCPULoad OUT, @sMemLoadKbytes OUT

However, SQL query analyser (& .NET) throws an exception starting with

Server: Msg 203, Level 16, State 2, Procedure usp_PM_PMProcessLoadsByProcesses_SUM, Line 24
[Microsoft][ODBC SQL Server Driver][SQL Server]The name 'SELECT @sCPULoad=sCL, @sMemLoadKbytes=sML FR

But I can't see the full error message because the actual string is too long for the debugger and gets clipped.

Full Procedure listing

ALTER PROCEDURE dbo.usp_PM_PMProcessLoadsByProcesses_SUM
(
@RemoteTable varchar(250),
@ProcessIDs varchar(250),
@TimePoint varchar(50),
@sCPULoad int OUTPUT,
@sMemLoadKbytes int OUTPUT
)

AS
DECLARE @queryText1 varchar(8000)
DECLARE @queryText2 varchar(8000)
DECLARE @queryText3 varchar(8000)

SET @queryText1 = 'SELECT ASProcessID, max(StatsTime) as mST FROM '
+ @RemoteTable +
' WHERE ASProcessID IN (SELECT ID FROM fnSplitStringToIDs(''' + @ProcessIDs + ''')) AND StatsTime <= ''' + @TimePoint + ''' GROUP BY ASProcessID'

SET @queryText2 = 'SELECT SUM(CpuLoad) AS sCL, SUM(MemLoadKbytes) AS sML FROM (' + @queryText1 + ')tTable INNER JOIN '
+ @RemoteTable + ' ON tTable.mST = ' + @RemoteTable + '.StatsTime AND tTable.ASProcessID = ' + @RemoteTable + '.ASProcessID'

SET @queryText3 = 'SELECT @sCPULoad=sCL, @sMemLoadKbytes=sML FROM (' + @queryText2 + ')'

EXEC @queryText3 @sCPULoad OUT, @sMemLoadKbytes OUT

RETURNStart Free Trial
[+][-]12.01.2005 at 01:56PM PST, ID: 15400338

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: output, multiple, procedure, parameters, stored
Sign Up Now!
Solution Provided By: acperkins
Participating Experts: 2
Solution Grade: A
 
 
[+][-]12.01.2005 at 01:56PM PST, ID: 15400340

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]12.01.2005 at 01:58PM PST, ID: 15400354

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.01.2005 at 02:05PM PST, ID: 15400414

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32