Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3851736
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:12:32+00:00 2026-05-19T17:12:32+00:00

I have a stored procedure in SQL Server 2005. It returns three variables in

  • 0

I have a stored procedure in SQL Server 2005. It returns three variables in one single line, like this (extremely simplified) example:

CREATE PROCEDURE proc1
AS
   DECLARE @col1 VARCHAR(4)
   DECLARE @col2 VARCHAR(4)
   DECLARE @col3 VARCHAR(4)
   SET @col1 = 'val1'
   SET @col2 = 'val2'
   SET @col3 = 'val3'

   SELECT @col1 col1, @col2 col2, @col3 col3
GO

In an external application, I need to execute the stored procedure and process one of the three values. Due to limitation in this application, It will always only use the very first column.

So, what I’m looking for is a way to limit the result set of the procedure to one column or rearrange the order of the columns.

IIRC MySQL supports subqueries like the following, but SQL Server does not:

SELECT col1 FROM (EXEC proc1)

I know that I can use a temporary table (or table variable) to buffer the result and then select one column, but I hope that there is a more “condensed” way than this:

CREATE TABLE #tmp (col1 VARCHAR(4) NOT NULL, col2 VARCHAR(4) NOT NULL, col3 VARCHAR(4) NOT NULL)
INSERT INTO #tmp EXEC proc1
SELECT col2 FROM #tmp
DROP TABLE #tmp

Thanks in advance for any hints you can give,

Patrick

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:12:32+00:00Added an answer on May 19, 2026 at 5:12 pm

    If you could convert the stored proc into a table valued function, you could select arbitrary columns from that. If you still need the stored proc (for some other system that can’t be changed), you can put all of the logic in the function, and get the stored proc to call that.

    Otherwise, if you can’t relocate the code from the stored proc, then going via a temp table is about the best you can do, I’m afraid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have coded three select statements in stored procedure in Microsoft SQL Server 2005.
I have a stored procedure in SQL Server 2005 with multiple variables and I
I have a very long-running stored procedure in SQL Server 2005 that I'm trying
I have a stored procedure on a SQL Server 2005 database which has a
Working in SQL Server 2005, I have a stored procedure that inserts a record
All, I have a stored procedure on SQL Server 2005 that accepts an XML
I have designed a stored procedure usign Sql Server 2005 below to compare 3
I have created a stored procedure in SQL Server 2005, also I create another
I am using SQL server 2005. I have a table like this - ID
I am using SQL server 2000. I have a stored procedure sitting on machine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.