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.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Bulk insert files with differing filenames

Author  Topic 

femig
Starting Member

5 Posts

Posted - 2004-05-25 : 04:29:08
i have several text files titled batch_registration_19881212.txt
The digits at the end are timstamps and each file dropped in the folder have different filenames based on the timstamp but they all begin with 'batch_registration_'.

i want to create a DTS Package that will import these files into a table.
Can anyone show me how to do this?
thx

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-05-25 : 12:27:28
You don't need DTS for this. To get the file names into a table, use xp_cmdshell with dir DOS command.

Tara
Go to Top of Page

bmanoj
Starting Member

13 Posts

Posted - 2004-05-25 : 12:55:58
Take a look at [url]http://www.databasejournal.com/features/mssql/print.php/3325731[/url]

Manoj
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-05-25 : 14:31:23
Something like...


INSERT Into Ledger_Folder
EXEC master..xp_cmdshell 'Dir d:\*.*'


Delete From Ledger_Folder_Parsed

Insert Into Ledger_Folder_Parsed (Create_Time, File_Size, File_Name )
Select Convert(datetime,Substring(dir_output,1,8)
+ ' '
+ (Substring(dir_output,11,5)
+ Case When Substring(dir_output,16,1) = 'a' Then ' AM' Else ' PM' End)) As Create_Time
, Convert(Int,LTrim(RTrim(Replace(Substring(dir_output,17,22),',','')))) As File_Size
, Substring(dir_output,40,(Len(dir_output)-39)) As File_Name
From Ledger_Folder
Where Substring(dir_output,1,1) <> ' '
And (Substring(dir_output,1,1) <> ' '
And Substring(dir_output,25,5) <> '<DIR>')

SELECT * FROM Ledger_Parsed



Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-05-25 : 14:34:58
ooops...here's the DDL



if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Ledger_Folder_Parsed]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Ledger_Folder_Parsed]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ledger_folder]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ledger_folder]
GO

CREATE TABLE [dbo].[Ledger_Folder_Parsed] (
[Create_Time] [datetime] NULL ,
[File_Size] [int] NULL ,
[File_Name] [varchar] (255) NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[ledger_folder] (
[dir_output] [varchar] (255) NULL
) ON [PRIMARY]
GO






Brett

8-)
Go to Top of Page
   

- Advertisement -