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
 Query between 2 servers
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dr223
Constraint Violating Yak Guru

361 Posts

Posted - 04/20/2012 :  09:38:18  Show Profile  Reply with Quote
Hi,

I have formulated the following query which works fine and links to Server1 and does the computation;

SELECT     TOP (100) PERCENT dbo.TblAuto_coll.Prac_no
FROM         dbo.TblAuto_coll INNER JOIN
                      Server1.[GPRD-RCT].dbo.Practice AS Practice ON dbo.TblAuto_coll.Prac_no = Practice.Practicecode
WHERE     (dbo.TblAuto_coll.col_status <> 'S')
ORDER BY dbo.TblAuto_coll.Prac_no


Ofcourse, I addlinked server as follows:

Use master
Go
EXEC sp_addlinkedserver
'Server1',
N'SQL Server'
GO

Now, I tried for another server same procedure and changed the query to;

SELECT     TOP (100) PERCENT dbo.TblAuto_coll.Prac_no
FROM         dbo.TblAuto_coll INNER JOIN
                      Server2.[GPRD-RCT].dbo.Practice AS Practice ON dbo.TblAuto_coll.Prac_no = Practice.Practicecode
WHERE     (dbo.TblAuto_coll.col_status <> 'S')
ORDER BY dbo.TblAuto_coll.Prac_no


I receive the error;

SQL Execution Error
Error Source: .Net SqlClient Data Provider
Error Message: Incorrect syntax near '-'



Why do I receive the error and the database name - GPRD-RCT exists in Server2 too, with the table Practice.

N/B: when I execute the query the line of code changes from
Server2.[GPRD-RCT].dbo.Practice AS Practice

to
Server2.GPRD - RCT.dbo.Practice AS Practice


Thank you

Edited by - dr223 on 04/20/2012 09:46:12

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 04/20/2012 :  14:49:09  Show Profile  Reply with Quote
where are you trying to run this editor? are you using default editor in ssms?

------------------------------------------------------------------------------------------------------
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.22 seconds. Powered By: Snitz Forums 2000