Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Two independent Select Statements in a stored Proc

Author  Topic 

reogeo
Starting Member

2 Posts

Posted - 2012-05-06 : 11:35:52
Hi all,

I want to include 2 independent select staments in a SP..

For example

Select A,B,C from Albhabets

Select 1,2 from numbers

And get the output as
A B C 1 2

Is it possible?
Why i need this is To avoid database roundtrips to make the execution time less..

Thanks in Advance

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-06 : 13:24:14
hmm...are the tables related in some way? if not how will you determine which row to be merged with which row from second table? it doest make any sense

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-05-06 : 17:21:24
I share Visakh's opinion on this. What you are trying to do seems like a marriage of convenience that is bound to cause a lot of problems.

Almost any method you use to connect to the database allows you to retrieve multiple recordsets and process them. For example in ADO.Net, if you are using ExecuteReader, you can use NextResult() method to move to the next result set. There is a nice and simple example here: http://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.80).aspx

If you are unable to do that and end up making two round trips to the database, you can mitigate the impact by making sure that the connection pooling can be used. http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx
Go to Top of Page
   

- Advertisement -