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)
 Exporting to flat files using query analyser

Author  Topic 

Mooj
Starting Member

2 Posts

Posted - 2006-11-28 : 11:38:39
All,

Does anyone know how to export data from SQL 2000 to a flat file using Query Analyser?

I have a SP that I want to run on a weekly basis. The SP looks at a table with a sequential counter column (identifier/autonumber), and then works out which records need archiving (this will produce a clause such as - WHERE ctrcode between 1009230 and 1013848). The SP then stores this information in the ARCHIVELOG table, and also stores some other information about the max and min records (such as dates they were created). I have the SP all written out, I just need to know what QA command to export data to a flat file is.

Cheers,

Mooj

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-11-28 : 12:32:36
http://weblogs.sqlteam.com/mladenp/archive/2006/07/25/10771.aspx
also read comments



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Mooj
Starting Member

2 Posts

Posted - 2006-11-29 : 10:30:52
Cheers for the help spirit1. The way I have done this is to use the following script:

SET @bcpsql = 'SELECT * FROM '+@dbname+'.dbo.DAILYSALES (nolock) WHERE ctrcode BETWEEN '+cast(@minctrcode as varchar)+' and '+cast(@maxctrcode as varchar)+''
SET @bcpstring = 'bcp "'+@bcpsql+'" queryout h:\'+@filename+' -n -t , -T -S '+@@servername
exec @archivesuccess = master..xp_cmdshell @bcpstring
Go to Top of Page
   

- Advertisement -