December 4, 2008 at 10:23 am
I need to do the following inside a stored procedure:
INSERT INTO DEV001\SQL2005DEV.myDataBase.myTable
SQL does not like the "\": Incorrect syntax near '\'.
I tried:
INSERT INTO [DEV001\SQL2005DEV].myDataBase.myTable.
I do not get a compile error but the insert does not insert any rows.
How do I handle the "\" in the server name?
December 4, 2008 at 10:35 am
Is this a linked server? If not you do not need the server name. You are also missing the schema in the 4 part naming. You need server.database.schema.table and you are missing schema.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
December 4, 2008 at 10:36 am
Hi Greg
Some of our older servers have similar names and I've worked around it successfully by using square brackets, as you suggest.
Have you ran the SELECT part of your INSERT on its own, to ensure that rows are returned for the INSERT?
Cheers
ChrisM
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
December 4, 2008 at 10:37 am
Yes, it's linked
December 4, 2008 at 10:38 am
Yes, I have run the insert on it's own without the server name, just the database name, and it works correctly.
December 4, 2008 at 10:40 am
Was the omission of schema a typo or is it missing?
Can you do a Select * from [DEV001\SQL2005DEV].myDataBase.SCHEMA.myTable across the linked server?
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
December 4, 2008 at 10:42 am
gregarobinson (12/4/2008)
Yes, I have run the insert on it's own without the server name, just the database name, and it works correctly.
Not the INSERT, the SELECT. What does it return?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
December 4, 2008 at 10:43 am
Can you post the whole INSERT statement?
INSERT INTO DEV001\SQL2005DEV...........
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
December 4, 2008 at 10:45 am
SELECT* from DEV001\SQL2005DEV.myDatabase.dbo.myTable returns:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '\'.
December 4, 2008 at 10:49 am
Well, I cannot tell you what's different but I just tried this:
INSERT INTO [DEV001\SQL2005DEV].myDatabase.dbo.myTable
and it worked. "dbo" has always been present so that is not a change.
December 4, 2008 at 10:53 am
gregarobinson (12/4/2008)
SELECT* from DEV001\SQL2005DEV.myDatabase.dbo.myTable returns:Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '\'.
Yes, I would have expected that which is why I used the "[]" around the linked server name.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
December 4, 2008 at 10:56 am
gregarobinson (12/4/2008)
Well, I cannot tell you what's different but I just tried this:INSERT INTO [DEV001\SQL2005DEV].myDatabase.dbo.myTable
and it worked. "dbo" has always been present so that is not a change.
This syntax looks fine...but you weren't getting any rows inserted (see original post). What's the rest of the statement?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
December 4, 2008 at 12:34 pm
Since you are on SQL Server 2005 - you might want to look into using synonyms instead of using the four-part naming convention in your code. I would recommend also creating a schema for the database on the linked server that you are accessing:
CREATE SCHEMA MyDatabase AUTHORIZATION dbo;
CREATE SYNONYM MyDatabase.MyObject
FOR [LinkedServer\Instance].MyDatabase.dbo.MyObject;
And now, in your code you would use:
INSERT INTO LocalTable
SELECT ...
FROM MyDatabase.MyObject;
Just a thought 😉
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply