Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 USE a QUERY to BCP from file to a table

Author  Topic 

Bex
Aged Yak Warrior

580 Posts

Posted - 2009-03-25 : 06:05:38
Hi there

I am trying to write a query to BCP data into a table from a data file. I have the following code:

bcp sainsburys.crdm.Header_20070530 in "SELECT * FROM OPENROWSET(BULK 'D:\crdm.Header_20070530.dat')" -T -c -E


But when I execute, I get the error:
Error = [Microsoft][sql Native Client] Unable to open BCP host data-file

THe file exists, and the path is correct.

Any ideas?

Thanks



Hearty head pats

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-25 : 06:07:06
BCP is NOT a T-SQL command. It is a MS-DOS application.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-25 : 06:12:51
Make sure the file exists in the Server's directory

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Bex
Aged Yak Warrior

580 Posts

Posted - 2009-03-25 : 06:21:59
Hi madhivanan and Peso

Thanks for your replies. As Peso pointed out, BCP utility is command line code, therefore, debugging SQL is made difficult (silly me). So I removed the TSQL statement, and ran it in Management Studio:

"SELECT * FROM OPENROWSET(BULK 'D:\crdm.Header_20070530.dat')"

I'm missing a format file and an alias. So I'm debugging in management studio, and once I am sure it is all correct, I shall then (and only then) put it in the BAT file.



Hearty head pats
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-25 : 07:21:33
SELECT * FROM OPENROWSET(BULK 'D:\crdm.Header_20070530.dat') as f


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -