SQL Adding & Editing Proc Resultset

I need to call a stored proc & both add a column to the resultset and rename the columns. Is there a cleaner way to do this apart from dumping the resultset in a temp table or variable table & writing a select off of that?
LensoloAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>I need to call a stored proc
exec the_proc_name

> both add a column to the resultset and rename the columns.
Explain in non-technical terms what exactly you're trying to pull off here, and more important why.
0
LensoloAuthor Commented:
I have to write a stored proc that bridges 2 systems. It calls a vendor written (unchangeable) stored proc and has to customize the resulting recordset to return it to another process that will call it. The changes are simple. I have to rename 3 columns & add a new column with a static value.
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
I'm sure there are multiple ways to pull this off, but the one that comes to mind is:
Create a #temp table with the columns named exactly how the SP returns it
Execute code like this to insert the results of the SP into that temp table
INSERT INTO #tmp (col1, col2, col3)
exec the_proc_name

Open in new window

ALTER #tmp to change the column names, add new column, then UPDATE #tmp with new column's static value
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

LensoloAuthor Commented:
Thanks. My question above is: "Is there a cleaner way to do this apart from dumping the resultset in a temp table or variable table & writing a select off of that? "

There may not be. I am just trying to find out if there is. If no one posts anything I'll accet your response as the solution.
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>My question above is:
Missed that.  You could play with something like this...
SELECT col1, col2, col3 as looky_here_a_new_column_name, column4, 'banana' as new_column_name
FROM EXEC the_proc_name

Open in new window

0
LensoloAuthor Commented:
That sounds ideal, buit I can't get it to work.
Create proc dbo.p_Test
As
Select 1 as Col1, 2 as Col2, 'Bananas' as Col3
GO

select Col1,Col2,Col3
from exec p_Test

Tells me "incorrect syntax near exec". and other tests with select * from exec p_test and various similar combinations aren't fruitful at the moment.
0
LensoloAuthor Commented:
I'll close this. Thank for your help Jim Horn. I really appreciate it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.