Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 30th, 2004, 05:34 PM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dashes in the server name , cannot run sql cmd

Hi All,
   Trying to run an sql statement

select * from employee a, DA-T-BACIM01.my_database_test.dbo.employee b
where a.employee_code=b.employee_no



I get the following error:
Error:170 at Line:1 Message:Line 1: Incorrect syntax near '-'.

I am trying to compare tables from one server to another. There are dashes in the server name.
Anyone know how I can bypass this problem?


Vin

Reply With Quote
  #2 (permalink)  
Old September 30th, 2004, 05:49 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Location: Clarksville, TN, USA.
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try

[DA-T-BACIM01].my_database_test.dbo.employee

some people do not remember to name things properly. This will also give you problems when trying to use windows authentication.

By the way, have you set-up a linked server to the other server?



Sal
Reply With Quote
  #3 (permalink)  
Old September 30th, 2004, 11:53 PM
Friend of Wrox
 
Join Date: Sep 2004
Location: New Delhi, Dekhi, India.
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

Hi,

SQL Server is ready to except any thing enclosed in square bracket. U can use balnk spaces also.U can use reserve words also as identifiers in this way.

Any table name, Server name, DB name with -, blank space etc which are not valid as per identifier naming convention must be enclose within [].

select * from employee a,
[DA-T-BACIM01].my_database_test.dbo.employee b
where a.employee_code=b.employee_no


This will work perfectly with SQL Server. But yes I am not sure how ur application is database nutral with such things.

Hope u got the point

B. Anant
Reply With Quote
  #4 (permalink)  
Old October 1st, 2004, 10:09 AM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

worked!!!!!!!!! You guys rock.

Reply With Quote
  #5 (permalink)  
Old October 1st, 2004, 10:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Naperville, IL, USA.
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

We have the same problem. The answer is to enclose the server name in brackets as in [server-name].

Another way around the problem and the brackets would be to rename the server, eliminating the dashes or replacing them with underscores. This would be DA_T_BACIM01.

Of course the best way was already missed - NEVER USE DASHES OR SPACES IN SQL SERVER OBJECT NAMES, use underscores instead! Dashes and spaces are a royal pain!


Rand
Reply With Quote
  #6 (permalink)  
Old October 4th, 2004, 04:37 AM
Friend of Wrox
 
Join Date: Sep 2004
Location: New Delhi, Dekhi, India.
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

rgerrald, have u ever tried to give a server name with underscores in?? U should try once. Install a server and give machine name like My_Server_2. See what does it say.





B. Anant
Reply With Quote
  #7 (permalink)  
Old June 20th, 2014, 03:02 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2014
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default dashes in column names

I have the same problem with dashes in MeSQL table column names. Unfortunately I can't change the column names.
I've tried everything - including your square brackets.
Please Help!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How Run .sql Script file in MS SQL Server 2000? aarkaycee SQL Server 2000 5 October 12th, 2009 06:43 AM
how to run .sql from cmd eclecticnancy SQL Server 2000 2 May 7th, 2007 02:51 PM
how to run .sql from cmd (mssql) eclecticnancy BOOK: Beginning SQL 0 May 4th, 2007 04:27 PM
Need help on MS SQL Server 005 Express INSERT cmd VictorVictor ASP.NET 2.0 Professional 7 November 23rd, 2006 02:12 AM



All times are GMT -4. The time now is 10:47 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.