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 |
|
pr4t3ekd
Starting Member
31 Posts |
Posted - 2009-12-08 : 19:14:46
|
| Hello,I have the following select statement:SELECT TOP 100 * FROM TABLEPlease provide me with code where i can extract this to location such as:\\server\folder\subfolder\file.txt File must include the headers.I am using SQL Server 2000Thank You |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
pr4t3ekd
Starting Member
31 Posts |
Posted - 2009-12-09 : 00:08:37
|
| hello, here is my solution:--use this to run & actually save fileDECLARE @path VARCHAR(8000), @bcpCommand varchar(2000)SET @path = '\\SERVER\' + 'DATA_' + CONVERT(CHAR(8), GETDATE()-1, 112) + '.txt'SET @bcpCommand = 'bcp "SELECT * FROM DATA" queryout "' SET @bcpCommand = @bcpCommand + @path + '" -T -c -t \t'EXEC master..xp_cmdshell @bcpCommand--to get headers, use a view called DATA and insert headers as a row itself.--e.g.SELECT 'COLUMN1 COL1, 'COLUMN2' COL2UNION ALLSELECT 'DATA', 'DATAFROM TABLE |
 |
|
|
|
|
|