Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 30th, 2004, 04:34 PM
Registered User
 
Join Date: Sep 2004
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

 
Old September 30th, 2004, 04:49 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
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
 
Old September 30th, 2004, 10:53 PM
Friend of Wrox
 
Join Date: Sep 2004
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
 
Old October 1st, 2004, 09:09 AM
Registered User
 
Join Date: Sep 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old October 1st, 2004, 09:31 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old October 4th, 2004, 03:37 AM
Friend of Wrox
 
Join Date: Sep 2004
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
 
Old June 20th, 2014, 02:02 AM
Registered User
 
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!





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 05:43 AM
how to run .sql from cmd eclecticnancy SQL Server 2000 2 May 7th, 2007 01:51 PM
how to run .sql from cmd (mssql) eclecticnancy BOOK: Beginning SQL 0 May 4th, 2007 03: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.