Solved

Execute (@query) result join with a table

Posted on 2013-11-16
3
367 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
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Sharath earned 500 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 40

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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