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)
 automatic export data from multiple table to seperate text files

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-05-14 : 10:47:12
Thomas writes "I wanna export data from all tables which begin with letter txt_
to seperate text file name as txtsmith.txt,txtgary.txt ..etc..
example: table name
txt_smith
txt_gary
txt_jery and more..

but the problem is I don't know specific table name and how many table in database with txt_(name).

The users will create the specific need of their reports and dump into 1 table as txt_(their name). Then the end of day or at the specific time mssql will export those table data to an text file with specific txtsmith.txt or txtgary.txt

I am using MsSql 2000

Please help."

nr
SQLTeam MVY

12543 Posts

Posted - 2003-05-14 : 11:30:28
Easy to do using bcp.

Do you mean there is a single table with a field into which is placed the user name or many tables called txt_name?
Both are easy

something like

declare @name varchar(128), @maxname varchar(128)
select @name = '', @maxname = max(name) from sysobjects where name like 'txt_%' and xtype = 'U'
begin
select @name = min(name) from sysobjects where name like 'txt_%' and xtype = 'U' and name > @name

declare @cmd varchar(1000)
select @cmd = 'bcp dbname..' + @name + ' out c:\' + @name + '.txt -Ssvrname -T -c'

exec (@cmd)
end

If all in one table then use a query in the bcp statement

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -