-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathX12_Import_Files.sql
33 lines (27 loc) · 1.03 KB
/
X12_Import_Files.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Declare @path As VarChar(128), @InputFileName As VarChar(128)
Set @path='C:\' -- Replace this with your folder
-- Get list of files in the directory:
If OBJECT_ID('tempdb..#DirectoryListing') Is Not Null Drop Table #DirectoryListing;
Create Table #DirectoryListing (
id int IDENTITY(1,1)
,InputFileName nvarchar(512)
,depth int
,isfile bit);
Insert #DirectoryListing (InputFileName,depth,isfile)
EXEC master.sys.xp_dirtree @path, 0, 1;
-- Target just X12 files
If OBJECT_ID('tempdb..#FilesForInput') Is Not Null Drop Table #FilesForInput;
Select InputFileName
Into #FilesForInput
From #DirectoryListing As DL
Where isfile = 1
And DL.InputFileName Like '???%' -- Put your filename criteria here
While Exists (Select InputFileName From #FilesForInput)
Begin
Set @InputFileName = (Select Top 1 InputFileName From #FilesForInput)
Print 'Exec dbo.usp_Import_X12 ' + @path + ',' + @InputFileName
Exec Sandbox.dbo.usp_Import_X12 @path, @InputFileName
Delete
From #FilesForInput
Where InputFileName = @InputFileName
End