07-18-07, 16:44 #1Registered User
- Join Date
- Feb 2004
Unanswered: Read a file name from network folder automatically for a BULK INSERT
Hi again all,
Is there a way to read a file name automatically from a network folder? I can successfully bulk insert from this particular folder. The next step is as I add files, I wish to bulk insert the latest file added so the program must make that determination and import that specific file. I can delete the older files if necessary and save them elsewhere but it would still be nice to be able to read the file name. I then wish to store the name of this file, whatever it is, into a field called "SourceFileName" in my table that I am bulk inserting into. Does anyone have an example in dynamic SQL? Thanks.
07-18-07, 16:53 #2Annie's Dog Walker
Provided Answers: 6Code:
- Join Date
- Nov 2004
- on the wrong server
DECLARE @FilePathToSQLFiles VARCHAR(2000) DECLARE @Path VARCHAR(2000) SET @FilePathToSQLFiles = 'C:\' CREATE TABLE #SQLFiles ( SQLFileName VARCHAR(2000)) SET @Path = 'dir /b "' + @FilePathToSQLFiles + '*.sql"' INSERT INTO #SQLFiles EXECUTE master.dbo.xp_cmdshell @PathIf one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry. Earnest Hemingway, A Farewell To Arms.