Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyphen in BCP database_name

Status
Not open for further replies.

nshen

Programmer
May 14, 2002
53
US
Hi! I have a database name that contains a hyphen '-' character. I can import table data into it by using DTS.
But BCP will throw it out as invalid character. I tried to put double quote, single quote around the database name in the BCP command without any sucess.

Any help is appreciated.
Regards, Nancy
 
have you tried Square Brackets [My-Database]

"Shoot Me! Shoot Me NOW!!!"
- Daffy Duck
 
Square bracket caused the login to fail.

Good thought though!
Regards, Nancy
 
can you post the code?

"Shoot Me! Shoot Me NOW!!!"
- Daffy Duck
 
I did a quick test using these two formats - both worked for me

bcp "abc-xxx..table1" out c:\temp\MyData.txt -T -c -q

bcp "SELECT * FROM [abc-xxx]..table1" queryout c:\temp\MyData.txt -T -c

used sql2000

Hope they work for you.


 
(1) in double quotes:
bcp "db-name..Customer" in Customer.txt -F 1 -b 3000 -c -o Customer.out -U sa -S (local) -e Customer.err -h "ORDER(CustomerID ASC), TABLOCK"
(2) in square bracket:
bcp [db-name]..Products in Products.txt -F 1 -b 13704 -c -o Products.out -U sa -S (local) -e Products.err -h "ORDER(CustomerID ASC), TABLOCK"

With double quotations, I got this error:
SQLState = 37000, NativeError = 170
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '-'.

But there is no hyphen in the import text file.

With square brackets, I got this error:
SQLState = 37000, NativeError = 4060
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database requested in login '[db-name]'. Login fails.

Tried on Windows 2000 Server SP3, Win NT4 SP6a, going against SQL Server SP2 or SQL Server 2000 SP3. Same results.

Connecting and creating tables from Transact/SQL like osql utility was fine.

Any hints are appreciated.
Regards, Nancy

 
That was it! [bigsmile] Thanks!!!!!
Regards, Nancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top