Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
kloepper
Yak Posting Veteran
77 Posts |
Posted - 2004-02-16 : 15:11:10
|
| I'm trying to import data from multiple text files into multiple tables that don't exist yet...so I'm using the procedure below.Is there a way to do this in DTS by creating an import for one file and then using it as a template to iterate over for the other text files?Thanks,PaulDECLARE @FileName varchar(255),@TableCreateTemplate nvarchar(4000),@SqlStatement nvarchar(4000)CREATE TABLE #FileList(FileName varchar(255))INSERT INTO #FileListEXEC master..xp_cmdshell'dir /b C:\'SET @TableCreateTemplate ='CREATE TABLE [$(TableName)]([Date] smalldatetime NOT NULL, [Open] smallmoney NOT NULL, [High] smallmoney NOT NULL, [Low] smallmoney NOT NULL, [Close] smallmoney NOT NULL, [Volume] int NOT NULL)'DECLARE FileList CURSORLOCAL FAST_FORWARD READ_ONLY FORSELECT FileName FROM #FileListOPEN FileListWHILE 1 = 1BEGINFETCH NEXT FROM FileListINTO @FileNameIF @@FETCH_STATUS = -1 BREAKSET @SqlStatement =REPLACE(@TableCreateTemplate,'$(TableName)',@FileName)EXEC (@SqlStatement) -- create tableSET @SqlStatement ='BULK INSERT [' + @FileName + ']FROM ''D:\My Investment Databases\Stock_Quotes\Quote_Data\AMEX\' +@FileName + ''''--EXEC (@SqlStatement) -- load dataENDCLOSE FileListDEALLOCATE FileListDROP TABLE #FileList |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|