[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

I need help with a Stored Procedure in SQL Server 2005

Posted on 2011-05-03
1
Medium Priority
?
150 Views
Last Modified: 2012-05-11
Hi Experts,
I have a SQL Server 2005 Stored Procedure spGetAccountInfo which takes one parameter.  When I execute it from SQL Server the syntax looks like this:
EXEC spGetAccountInfo '1'

and it returns the following fields:
AccountID, AccountNo, AccountName, AccountCode, and Type

I want to create a new Store Procedure that calls this Stored Procedure (spGetAccountInfo) but only returns the AccountName and AccountCode columns for the AccountID i pass in as a parameter.

How can I do this?

Thanks in advance,
mrotor
0
Comment
Question by:mainrotor
1 Comment
 
LVL 23

Accepted Solution

by:
wdosanjos earned 2000 total points
ID: 35514653
You can achieve it by using a table variable or a temp table depending on the number of rows returned (if too many rows use a temp table).  Something like this:

DECLARE @temp table (
AccountID bigint, 
AccountNo varchar(50), 
AccountName varchar(100), 
AccountCode varchar(50), 
Type bigint)

INSERT INTO @temp
    EXEC spGetAccountInfo '1'

SELECT AccountName, AccountCode
   FROM @temp

Open in new window


Or,


CREATE TABLE #temp (
AccountID bigint, 
AccountNo varchar(50), 
AccountName varchar(100), 
AccountCode varchar(50), 
Type bigint)

INSERT INTO #temp
    EXEC spGetAccountInfo '1'

SELECT AccountName, AccountCode
   FROM #temp

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

872 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