Friday, February 24, 2012

Bulk Insert

Hi GUYS

My name is Jackson. I have been strugling to get the BULK INSERT statement import data from a text file to the database. Have a look at this piece of coding:

DECLARE @.SQL VARCHAR(1000)

set @.SQL =
'BULK INSERT dbo.#temp
FROM ''C:\Documents and Settings\mmelestj\Desktop\Dekany.txt''
WITH (FIELDTERMINATOR = '','', ROWTERMINATOR
= ''\n'')'

EXEC (@.SQL)

select id Site_Number ,fld2 Site_Name from #temp

The thing is I get the following error message:

Server: Msg 4861, Level 16, State 1, Line 1
Could not bulk insert because file 'C:\Documents and Settings\mmelestj\Desktop\Dekany.txt' could not be opened. Operating system error code 3(The system cannot find the path specified.).My guess is it doesn't like spaces in your statement [Documents and Settings].

I don't think you would be able to select from #temp because bulk insert is a separate process and #temp is available within one process only.

No comments:

Post a Comment