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 |
|
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 2000Please 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 easysomething likedeclare @name varchar(128), @maxname varchar(128)select @name = '', @maxname = max(name) from sysobjects where name like 'txt_%' and xtype = 'U'beginselect @name = min(name) from sysobjects where name like 'txt_%' and xtype = 'U' and name > @namedeclare @cmd varchar(1000)select @cmd = 'bcp dbname..' + @name + ' out c:\' + @name + '.txt -Ssvrname -T -c'exec (@cmd)endIf 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. |
 |
|
|
|
|
|