amitabh04
asked on
bulk insert
Hi,
1) I am trying to execute the following in query analyzer. The file c:\converted.txt exists on the server. I am actually logged on the server but get error message "Cannot bulk load. The file "c:\converted.txt" does not exist."
BULK INSERT winpayuncashed FROM 'c:\converted.txt'
WITH (
DATAFILETYPE = 'char',
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
);
GO
2) How can I file path as parameter in the command.
Thanks a lot for your help.
1) I am trying to execute the following in query analyzer. The file c:\converted.txt exists on the server. I am actually logged on the server but get error message "Cannot bulk load. The file "c:\converted.txt" does not exist."
BULK INSERT winpayuncashed FROM 'c:\converted.txt'
WITH (
DATAFILETYPE = 'char',
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
);
GO
2) How can I file path as parameter in the command.
Thanks a lot for your help.
Hello there,
to use the filepath as a parameter you would have to create a stored procedure for the bulk import like this:
Create Procedure dbo.bulkImportwinpayuncash ed(@FilePa th varchar(300))
as
BULK INSERT winpayuncashed FROM ''' +@FilePath+'''
WITH (
DATAFILETYPE = 'char',
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
);
Then you should be able to run the following command:
exec bulkImportwinpayuncashed "C:\converted.txt"
to use the filepath as a parameter you would have to create a stored procedure for the bulk import like this:
Create Procedure dbo.bulkImportwinpayuncash
as
BULK INSERT winpayuncashed FROM ''' +@FilePath+'''
WITH (
DATAFILETYPE = 'char',
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
);
Then you should be able to run the following command:
exec bulkImportwinpayuncashed "C:\converted.txt"
ASKER
Hi,
Still get error message "Cannot bulk load. The file "c:\converted.txt" does not exist"
Thanks a lot.
Still get error message "Cannot bulk load. The file "c:\converted.txt" does not exist"
Thanks a lot.
Is the user running this script able to access the location where the file is stored? Most of the times, SQL is running under a system account or a different account than the user logged on to the server, so maybe it's a simple permission issue? Can you try to put the converted.txt file into the same directory where your SQL database resides? And then just use the path "converted.txt" without any absolute path names? It should try to read the file from within the SQL data directory then.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
What you mean "path is of the SQL Server system " and not other system?
Thanks.
What you mean "path is of the SQL Server system " and not other system?
Thanks.
https://www.experts-exchange.com/questions/23037605/Problem-Passing-a-Path-Filename-as-an-Input-Parameter-for-a-Bulk-Insert.html