Using Double Quoted Identifiers In Linked Servers
- 2
- Add a Comment
The other day I was trying to obtain connection information from master.dbo.sysprocesses via a linked server call using SQL Server 2005. So the statement I was running looked like this:
INSERT INTO connection
SELECT DISTINCT [name],
hostname,
program_name,
loginame,
nt_username,
net_address,
last_batch,
getdate()
FROM OPENQUERY(”SQL1\V01″, ‘SELECT d.[name], p.hostname, p.program_name, p.loginame, p.nt_username, p.net_address, p.last_batch, getdate() FROM master.dbo.sysprocesses as p inner join master.dbo.sysdatabases as d on p.dbid = d.dbid‘)
When I execute the insert\select statement it works in a query window. However, when I run this statement in a job step the step fails. The error message states that there is an incorrect syntax near SQL1\V01. So after much frustration I switched from double quote identifiers to brackets. You know what… it worked! I was not able to find much information in BOL and the Internet about this “nuance”. So I now use brackets when referencing instance names via linked server calls. Has anyone run into this issue before? Let us know!

2 Comments
Ryan
March 5th, 2009
at 3:32am
Sounds like you got on the wrong end of some string parsing. Changing the query to the following should also work:
INSERT INTO connection
SELECT DISTINCT [name],
hostname,
program_name,
loginame,
nt_username,
net_address,
last_batch,
getdate()
FROM OPENQUERY(\”SQL1\V01\″, ‘SELECT d.[name], p.hostname, p.program_name, p.loginame, p.nt_username, p.net_address, p.last_batch, getdate() FROM master.dbo.sysprocesses as p inner join master.dbo.sysdatabases as d on p.dbid = d.dbid‘)
propecia
June 5th, 2009
at 3:28pm
I bookmarked this site, Thank you for good job!