Solved

Execute (@query) result join with a table

Posted on 2013-11-16
3
362 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Troubleshooting Methodology - steps 3 36
Convert SP in a format for debugging 7 30
CROSS APPLY 4 45
Using CTE to insert records into a table 2 29
In this article I will describe the Copy Database Wizard 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.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now