| Author |
Topic |
|
bonekrusher
Starting Member
44 Posts |
Posted - 2008-10-29 : 10:48:33
|
| Hi, I have 2 stored procedures that return the followingsp1:Partno-------12324146788sp2:Partno------12324134577How do I do the following:Query1: a LEFT JOIN Query2: a NOT IN (for example, Partno found in sp1 and NOT IN sp2)Thanks |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-29 : 10:51:44
|
| http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/26/select-columns-from-exec-procedure-name-is-this-possible.aspxMadhivananFailing to plan is Planning to fail |
 |
|
|
bonekrusher
Starting Member
44 Posts |
Posted - 2008-10-29 : 11:09:31
|
| Hi,OPENROWSET is for including all connection information that is required to access remote data from an OLE DB data source. I need to perform the query from the a T-SQL statement. For this purpose I am using SSME.Any other ideas? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-29 : 11:18:42
|
use the first approach using two temporay tables like belowCREATE TABLE #Temp1(Partno int)CREATE TABLE #Temp2(Partno int)INSERT #Temp1EXEC sp1....INSERT #Temp2EXEC sp2.....SELECT *FROM #Temp1 t1LEFT JOIN #Temp2 t2on t2.partno=t1.partnoSELECT * FROM #Temp1 t1WHERE t1.Partno NOT IN (SELECT Partno FROM #Temp2)... |
 |
|
|
ursangel
Starting Member
17 Posts |
Posted - 2008-10-29 : 11:23:03
|
| If both SP's return the same result, and you need to join the 2 means, why cant you go for a Single SP and apply your filter there.Is bothe the SP's deealing with the same tables? with diff where clause? Please provide the query and table structure.RegardsAngel |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-10-29 : 11:24:45
|
| Did you read the first bit of the link?Is there some reason you can't do a1)Create temp table with same columns (exactly) as returned by sp2)Do an INSERT EXEC with a call to that sp.For exampleINSERT #t EXEC <yourSp>-------------Charlie |
 |
|
|
bonekrusher
Starting Member
44 Posts |
Posted - 2008-10-29 : 11:43:45
|
| Thanks... How do I drop the table #Temp1 and #Temp2?When I try:DROP TABLE #Temp1I get:Msg 3701, Level 11, State 5, Line 1Cannot drop the table '#Temp1', because it does not exist or you do not have permission. |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-10-29 : 11:47:26
|
| Check they exist firstIF OBJECT_ID('tempdb..#temp1') IS NOT NULL DROP TABLE #temp1-------------Charlie |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-10-29 : 11:48:09
|
| Or, if you don't have permissions, have a chat with the sql server administrator. Unless that's you?-------------Charlie |
 |
|
|
bonekrusher
Starting Member
44 Posts |
Posted - 2008-10-29 : 12:00:42
|
| Thanks...IF OBJECT_ID('tempdb..#temp1') IS NOT NULL DROP TABLE #temp1Worked! |
 |
|
|
|