Solved

Execute (@query) result join with a table

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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Backup & Restore 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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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