Solved

Execute (@query) result join with a table

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

16 Experts available now in Live!

Get 1:1 Help Now