September 8, 2011 at 6:07 pm
I have to use bcp to import a text file from my computer. I am getting the above error and not sure why. Here is my code and any help is appreciated.
bcp tempdb.dbo.DimProducts in
"c:\Users\Shay\Documents\DimProducts.txt" -T -c
September 8, 2011 at 6:44 pm
There's no error message listed. What's the error?
September 8, 2011 at 6:54 pm
I apologize here is the error message.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.
September 8, 2011 at 7:57 pm
Hope this helps :
http://msdn.microsoft.com/en-us/library/ms162802.aspx
Cheers,
- Win.
" Have a great day "
September 8, 2011 at 8:09 pm
The syntax should be:
bcp "tempdb.dbo.DimProducts" in "c:\Users\Shay\Documents\DimProducts.txt" -T -c
September 8, 2011 at 8:19 pm
The following article has additional information on the BCP Utility:
http://www.simple-talk.com/sql/database-administration/working-with-the-bcp-command-line-utility/
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
September 8, 2011 at 8:25 pm
bcp [tempdb].[dbo].[DimProducts] in
"c:\Users\Shay\Documents\DimProducts.txt" -c -t
You don't use BCP from Query Analyzer. You run it from a command-line window.
you should use -c and not -C. The spacing should be OK, though.
I have not tested this, but still a hope..
Cheers,
- Win.
" Have a great day "
September 8, 2011 at 8:32 pm
Denny,
if we use this from analyzer it wil throw error as its a command not sql syntax.
bcp "tempdb.dbo.DimProducts" in "c:\Users\Shay\Documents\DimProducts.txt" -T -c
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'in'.
Cheers,
- Win.
" Have a great day "
September 9, 2011 at 5:06 am
As stated this shouldn't be run from Query Analyzer. It should be run from a command prompt on the machine's console which has the file on it. If the file is on a network share you'll probably want to specify the network path instead of a local drive.
September 12, 2011 at 7:47 pm
I can not get this to work for nothing. I tried putting the code in the command prompt and it just keeps opening up the data in notepad.
September 12, 2011 at 7:57 pm
What is the syntax?
Could you include the DDL and the Data for the file so that I can test?
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
September 13, 2011 at 1:27 pm
mzzzshay (9/12/2011)
I can not get this to work for nothing. I tried putting the code in the command prompt and it just keeps opening up the data in notepad.
Please post the exact syntax you are running in the command window.
September 13, 2011 at 2:37 pm
I gave you an example early on that was based on the Adventureworks2008 Database.
If I'm not familiar with something and I'm getting errors, I have tried running the example.
Often this points you in the right direction.
Did you take the time to read the article that I posted?
Just stating I can't get it to work does not provide any insight.
http://www.simple-talk.com/sql/database-administration/working-with-the-bcp-command-line-utility/
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
September 13, 2011 at 4:35 pm
MrDenny, thanks for continuing to try to help me.
This is my exact code that I am copying to the dos command prompt
bcp DimProducts in Documents\DimProducts.txt -T -c
This is the error message I am now getting:
SQLState = $0002, NativeError = 208
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server] Invalid obeject name 'DimProducts'.
September 13, 2011 at 4:45 pm
bcp DimProducts in Documents\DimProducts.txt -T -c
This is the error message I am now getting:
SQLState = $0002, NativeError = 208
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server] Invalid obeject name 'DimProducts'.
OK, this is because BCP doesn't know which database to find your table in. You've got two options (I'll show you both below). The first is to include the database own schema name (usually dbo) in the first parameter after BCP. Assuming that the database is called MyDatabase and the schema is dbo it would look like this.
bcp MyDatabase.dbo.DimProducts in Documents\DimProducts.txt -T -c
The second option is to use the -d parameter. Again assuming that the database is named MyDatabase and the owner is dbo.
bcp dbo.DimProducts in Documents\DimProducts.txt -T -c -d MyDatabase
Either option will work. Personally I prefer the first one.
Viewing 15 posts - 1 through 15 (of 21 total)
You must be logged in to reply to this topic. Login to reply