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
 SQL Server Development (2000)
 Exporting to TXT file

Author  Topic 

CLages
Posting Yak Master

116 Posts

Posted - 2006-10-20 : 12:29:07
hi,
i would like to know how to Export a Table to TXT file without using DTS.

A few weeks ago somebody sent to me a Sample, but i Lost.
Searching im FAQ i did not anything

tks for nay reply

Clages

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-10-20 : 12:37:14
Take a look at this topic, on using BCP to do it
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=73728
Go to Top of Page

CLages
Posting Yak Master

116 Posts

Posted - 2006-10-20 : 13:18:10
I found this and help me

But i Still remember something where i run into
Query analizer.

Tks Anyway
Clages




posted on Wednesday, October 26, 2005 5:19 AM by Madhivanan
BCP - Export data to Text File

Here is a simple method of exporting all the data from SQL Server table to a Text File

CREATE Procedure BCP_Text_File
(
@table varchar(100),
@FileName varchar(100)
)
as
If exists(Select * from information_Schema.tables where table_name=@table)
Begin
Declare @str varchar(1000)
set @str='Exec Master..xp_Cmdshell ''bcp "Select * from '+db_name()+'..'+@table+'" queryout "'+@FileName+'" -c'''
Exec(@str)
end
else
Select 'The table '+@table+' does not exist in the database'




Execute this procedure by giving Table Name and the File Name

EXEC BCP_Text_File 'Employee','C:\emp.txt'

Now all the data from Employee table will be exported to the text file which will be located at C:\emp.txt
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-21 : 06:34:17
Thanks. You need to run the procedure in QA by supplying values to parameters

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -