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 2005 Forums
 Transact-SQL (2005)
 OPENQUERY to pull data from 2 Tables in 2 Servers

Author  Topic 

yazasi
Starting Member

11 Posts

Posted - 2008-10-17 : 00:23:03
I have the following two servers with two tables that have two columns in common which are: (Customer_ID) and (Customer_Key_NO)that have the same data. What I need to do is to pull all customer info from Table_2 where column Management_Area_Code has one of these codes: 'A!' or '?B' or '=C' knowing that this column can have a wildcard such as: A! ?B =C ~X /F


Server_1
Table_1
Customer_ID
Management_Area_Code

Server_2
Table_2
Customer_Key_No
Address
City
State
Zip_Code

The query I've used is:

SELECT *
FROM OPENQUERY (Server_2, 'SELECT Customer_Key_No,Address,City,State,Zip_Code
From Table_2')I
INNER JOIN Table_1 K
ON K.Customer_ID = I.Customer_Key_No
Where Management_Area_Code LIKE ''A!'' or
Management_Area_Code LIKE ''?B!''

-- I'm getting this error: --
-- Msg 170, Level 15, State 1, Line 7 --
-- Line 7: Incorrect syntax near 'A'. --

Can anyone help with this one?.

Thanks.






tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-17 : 00:28:02
Why are you using double quotes around A and B?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

yazasi
Starting Member

11 Posts

Posted - 2008-10-17 : 00:30:48
I'm using SQL 2005 and that's what it takes, when I use sibgle quotes it give million of errors.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-17 : 11:35:37
SQL Server 2005 does not require double quotes.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

yazasi
Starting Member

11 Posts

Posted - 2008-10-18 : 01:22:36
Tara, when I put the single quotes it gives me an error stating that the table view could not be located. and when I use a "simple query" with double quotes it does return rows needed.

Thanks.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-18 : 02:08:02
quote:
Originally posted by yazasi

Tara, when I put the single quotes it gives me an error stating that the table view could not be located. and when I use a "simple query" with double quotes it does return rows needed.

Thanks.


single quotes will work. Are you sure you're running this code on server1?
Go to Top of Page

malaytech2008
Yak Posting Veteran

95 Posts

Posted - 2008-10-18 : 23:39:18
use single quotes instead of double quotes.single works fine in SQL server 2005

malay
Go to Top of Page

yazasi
Starting Member

11 Posts

Posted - 2008-10-20 : 02:01:25
Will do. Thanks.
Go to Top of Page

yazasi
Starting Member

11 Posts

Posted - 2008-10-20 : 21:42:11
It kept giving me an error when I used the single quote. However, it did work with the double quotes. Don't ask me how, but this is what it is :)

Thank all for the help. I really appreciated. I'm new to this forum and I realized it is a big help to everyone beginers and pros.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-20 : 23:45:12
quote:
Originally posted by yazasi

It kept giving me an error when I used the single quote. However, it did work with the double quotes. Don't ask me how, but this is what it is :)

Thank all for the help. I really appreciated. I'm new to this forum and I realized it is a big help to everyone beginers and pros.


can you show final query used?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-21 : 04:22:38
Try


SELECT *
FROM OPENQUERY (Server_2, 'SELECT Customer_Key_No,Address,City,State,Zip_Code
From Table_2')I
INNER JOIN Table_1 K
ON K.Customer_ID = I.Customer_Key_No
Where Management_Area_Code LIKE 'A!' or
Management_Area_Code LIKE '?B!'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -