SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 inner join table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

peace
Constraint Violating Yak Guru

279 Posts

Posted - 04/24/2012 :  03:49:36  Show Profile  Reply with Quote
i would like to know which of the following in table1 who has bought the code ABC.
but i get this error:Invalid object name table1

SELECT *
FROM openquery
( [testing] ,

'
select A.ID,FirstName,LastName
from
(select * from table1)A
inner join
(select ID
from table2 with (nolock)
where code in (''ABC'')
)B
on A.ID = B.ID
')

visakh16
Very Important crosS Applying yaK Herder

India
47099 Posts

Posted - 04/24/2012 :  21:42:05  Show Profile  Reply with Quote
do you've table table1 present in server referred by testing?

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

Go to Top of Page

peace
Constraint Violating Yak Guru

279 Posts

Posted - 04/24/2012 :  21:58:12  Show Profile  Reply with Quote
I'm accessing using table1 db.
Then I use the openquery which is testing to select the inner join on table2
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47099 Posts

Posted - 04/24/2012 :  22:24:20  Show Profile  Reply with Quote
is table1 a db?

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

Go to Top of Page

peace
Constraint Violating Yak Guru

279 Posts

Posted - 04/24/2012 :  22:32:45  Show Profile  Reply with Quote
table1 is a table
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47099 Posts

Posted - 04/24/2012 :  22:40:57  Show Profile  Reply with Quote
then what do you mean by

I'm accessing using table1 db.


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

Go to Top of Page

peace
Constraint Violating Yak Guru

279 Posts

Posted - 04/24/2012 :  22:53:32  Show Profile  Reply with Quote
Oh I connect to the DB which can straight run select * from table1
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47099 Posts

Posted - 04/25/2012 :  00:34:58  Show Profile  Reply with Quote
so table2 is in [testing] ?

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

Go to Top of Page

peace
Constraint Violating Yak Guru

279 Posts

Posted - 04/25/2012 :  02:21:41  Show Profile  Reply with Quote
Yes that is correct
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47099 Posts

Posted - 04/25/2012 :  14:39:33  Show Profile  Reply with Quote
then shouldnt it be this?


select A.ID,FirstName,LastName
from table1 A
inner join
(select * from openquery
( [testing] ,'select ID 
from table2 with (nolock)
where code in (''ABC'')')
)B
on A.ID = B.ID


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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000