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.
| Author |
Topic |
|
albertkohl
Aged Yak Warrior
740 Posts |
Posted - 2010-04-14 : 19:10:51
|
| is there any way to feed the results of a stored procedure into selects on a query???for example something like this:select * from mytable where zip in (exec radius @zip=29577,@distance=35) |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-04-14 : 19:34:31
|
Dump the results of the stored proc into a temp table, like this:CREATE PROCEDURE uspTestProc@param INTAS SELECT @param * 1 AS valUNION ALL SELECT @param * 2UNION ALL SELECT @param * 3GOCREATE TABLE #tmp (v INT)INSERT INTO #tmpEXEC uspTestProc 2SELECT * FROM Production.Product pINNER JOIN #tmp t ON p.ProductID = t.vGODROP TABLE #tmpGODROP PROCEDURE uspTestProcGO ------------------------------------------------------------------------------------Any and all code contained within this post comes with a 100% money back guarantee. |
 |
|
|
albertkohl
Aged Yak Warrior
740 Posts |
Posted - 2010-04-14 : 19:42:11
|
| only thing is the query changes ALL the time... and can have any number of other selects in the where clause... is there any way to just have SQL Join against the results or something? rather than dumping to a table, than joining against that... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
albertkohl
Aged Yak Warrior
740 Posts |
Posted - 2010-04-15 : 12:23:20
|
| Perfect, thanks a lot! |
 |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-04-15 : 13:56:36
|
quote: Originally posted by madhivanan Refer method 2http://beyondrelational.com/blogs/madhivanan/archive/2007/11/24/select-columns-from-exec-procedure-name-is-this-possible.aspx
Be careful using OPENROWSET like this. It has the potential to create deadlock issues (See the example below). Also, if you're not using a trusted connection, then you'll have to pass it a password from within the TSQL that calls it. Finally, because you have to specify a server name, if you move the database to another server, it will continue to reference the original server. Run this script on the AdventureWorks database to see an example of the deadlocking issue created bu OPENROWSET. Basically, it occurs because the stored procedure is executed under a different connection. it will wait for any locks held by the transaction of the first connection, which wont be released until OPENROWSET returns. USE AdventureWorksGOCREATE PROCEDURE uspGetProdName@ProductID INTAS SELECT ProductID, Name FROM Production.Product WHERE ProductID = @ProductIDGOBEGIN TRANSACTIONUPDATE Production.ProductSET Name = 'zzzAdjustable Race'WHERE ProductID = 1SELECT * FROMOPENROWSET('SQLOLEDB', 'Data Source=YOUR_SERVER_NAME;Trusted_Connection=yes;Integrated Security=SSPI', 'Execute AdventureWorks.dbo.uspGetProdName 1')COMMIT TRANSACTIONGO------------------------------------------------------------------------------------Any and all code contained within this post comes with a 100% money back guarantee. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-04-16 : 04:49:22
|
Thanks. I will keep that in mind MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|