January 23, 2012 at 4:54 am
Hi All,
How to run two queries in parallel (not one by one) ? except 1) run in 2 query windows 2) run in 2 jobs.
Have to run 2 queries in single query window/ in single job.
Thanks and Regards,
Ravi.
January 24, 2012 at 6:53 am
I see [two] possible solutions to the "running two queries in the same window/'job' at the same time" question:
SELECT col1, col2 FROM table1 -- Query #1
UNION
SELECT col1, col2 FROM table2 -- Query #2
...or...
SELECT a.col1, b.col2 FROM
(SELECT col1, col2 FROM table1) a -- Query #1
INNER JOIN
(SELECT col1, col2 FROM table2) b -- Query #2
ON a.col1 = b.col1
There you have it folks. Two queries executed at the same time, same "job". Tada.
January 24, 2012 at 6:59 am
Thanks for your reply.
My query is,how we can run single query using two databases in single query window in parellel?
Thanks and Regards,
Ravi
January 24, 2012 at 7:46 am
You can't. That requires multithreading which a single query window in SSMS does not do. Why do they have to run at the same time? Unless you do something like the union described you can't even be sure the engine runs both queries at the exact same moment.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 24, 2012 at 7:49 am
Reading your post again I think you are asking how to retrieve data from 2 databases at once? You can query across databases quite easily. If they are on the same server it is really simple.
select [columns] from database.schema.table
You could use the union idea above and the second query would query your second database.
select [columns] from SomeTable
union all
select [columns] from OtherDataBase.dbo.OtherTable
Is that what you are looking for?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply