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
 Transact-SQL (2000)
 output to csv

Author  Topic 

ccrespo
Yak Posting Veteran

59 Posts

Posted - 2007-08-10 : 14:44:37
is there any way to get this out into csv?

DECLARE @FileName varchar(50),
@bcpCommand varchar(2000)


SET @FileName = 'c:\globalasatest.csv'
--SET @FileName = REPLACE('c:\authors_'+CONVERT(char(8),GETDATE(),1)+'.txt','/','-')

SET @bcpCommand =
'bcp "SELECT * FROM master..sysobjects" queryout "'
SET @bcpCommand = @bcpCommand + @FileName + '" -U testuser -P testuser -c'

EXEC master..xp_cmdshell @bcpCommand

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-08-10 : 14:47:10
First use a cmd window to make sure you got the syntax right, then use xp_cmdshell.

From a cmd window:
bcp "SELECT * FROM master..sysobjects" queryout C:\temp\SomeFile.csv -Sserver1 -T -c -t, -r\r\n

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -