Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How to check if the file exists or not before bulk insert

$
0
0

How to check if the file exists or not before bulk insert.

I would like to skip the bulk insert if the file doesn't exist.

Information:

I use Stored Procedures to run Bulk insert statement.

The stored procedures is call by package.

******************

I test it at query analyzer and show the error when file don't exists.

Error message

Server: Msg 4860, Level 16, State 1, Line 1
Could not bulk insert. File 'E:\POLL41.fmt' does not exist.

*****************

Code

CREATE PROCEDURE sp_InsertPoll59
AS
declare @strsql varchar(5000)

select @strsql = 'BULK INSERT POLL59 '
select @strsql = @strsql +' FROM ''E:\POLL.DWN'''
select @strsql = @strsql +' WITH (FORMATFILE = ''E:\POLL.fmt'')'
exec(@strsql)
GO


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>