E-Mail:
Get our new Windows 7 eBook (PDF) for $7 with 70+ Tips. Download Now!

Using Double Quoted Identifiers In Linked Servers

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_usernamep.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

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‘)

I bookmarked this site, Thank you for good job!

What Do You Think?

 

Posted Recently

40 queries / 0.188 seconds.