Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Execute (@query) result join with a table

Posted on 2013-11-16
3
Medium Priority
?
378 Views
Last Modified: 2013-11-17
Dear Experts,
I have a result of query in @Query which is showing data properly. I have to joint that result with the table result_mst on transno (both side). How could I do that, please guide.

Screen
0
Comment
Question by:Mehram
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
Sharath earned 1500 total points
ID: 39653393
Create a table with all columns returned from the result of sproc execution.
Now join both the tables. Here is pseudo code.

CREATE TABLE #Query_Result(TransNo uniqueidentifier, ExamCode varchar(10))
-- Add all other columns to this table
-- You can go with temp table or table variable

INSERT #Query_Result
EXECUTE(@Query)

SELECT *
  FROM result_mst a
 JOIN #Query_Result b on a.TransNo = b.TransNo

Open in new window

0
 

Author Comment

by:Mehram
ID: 39654166
The @query number of columns not confirm. Is there any possibility to insert @query result into temp table directly instead of creating #query_result table because no of column is not confirm

Please see code:
SET @query = N'SELECT Transno, ExamCode,'
             + @slct
             + ' FROM (SELECT Transno,ExamCode,SN,ObtMarks FROM #Result) AS p PIVOT ( MAX([ObtMarks]) FOR SN IN ( '
             + @cols
             + ' )) AS pvt ORDER BY Transno, ExamCode;'

--SELECT @query


Into #Query_Result
EXECUTE(@query)

Open in new window

0
 
LVL 41

Expert Comment

by:Sharath
ID: 39654785
You can do that in your dynamic SQL itself. Are you still looking for help here?
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

597 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