December 9, 2011 at 2:05 am
I am creating stored procedures which down load files, rename files and import files. This is going to be running on a schedule.
The file the script is picking up may not always be there becuase they are files coming from the web. Therefore if the job runs and there is not a file there you get an error. Is there a way to only run if there is a file with the requested name.
If I have not been clear enough please ask and I will try to explain further
December 9, 2011 at 3:44 am
create one batch file which checks for the required files, then involve this if files exists.
December 9, 2011 at 4:04 am
I am thinking of using the following. Could you show me what you would do to look at the required files.
USE HBSLIVE
GO
CREATE TABLE CSVTest
(ID INT,
FirstName VARCHAR(40),
LastName VARCHAR(40),
BirthDate SMALLDATETIME)
GO
BULK
INSERT CSVTest
FROM 'c:\csvtest.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = ''
)
GO
--Check the content of the table.
SELECT *
FROM CSVTest
GO
--Drop the table to clean up database.
SELECT *
FROM CSVTest
GO
December 9, 2011 at 4:25 am
I would use a TRY ... CATCH routine to check for the FILE EXISTS condition.
http://msdn.microsoft.com/en-us/library/ms175976.aspx
---
Note to developers:Want to get the best help? Click here https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help (Jeff Moden)
My blog: http://uksqldba.blogspot.com
Visit http://www.DerekColley.co.uk to find out more about me.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply