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)
 Export comma delimited txt file

Author  Topic 

vladimir_grigoro
Yak Posting Veteran

62 Posts

Posted - 2002-02-25 : 04:07:27
Hi,
I am trying to export data into txt file using this example:
[/b]
DECLARE @FileName varchar(50),
@bcpCommand varchar(2000)

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

SET @bcpCommand = 'bcp "SELECT * FROM pubs.dbo.authors ORDER BY au_lname" queryout "'
SET @bcpCommand = @bcpCommand + @FileName + '" -U sa -P -c'

print @bcpCommand

EXEC master..xp_cmdshell @bcpCommand[/b]

Everything is fine but I want use different type of ".txt" file -comma delimited and to specify that the char fields should be with "..." and integer without. The parameter "-c" is for tab delimited file How I could change it?

nr
SQLTeam MVY

12543 Posts

Posted - 2002-02-25 : 09:41:09
look at the -t switch to change the field terminator.

To get the quoted delimitters is a bit more tricky I think.
Could probably do it with a format file - I usually generate a view to do the bcp from and that puts quotes round the string characters for me.

==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page

vladimir_grigoro
Yak Posting Veteran

62 Posts

Posted - 2002-02-25 : 10:27:08
Thanks nr,
I have already found the -t switch but I still have the problem with text delimitter. Your idea is sounds pretty well but I will continue to search for a switch to do that. But who knows...

quote:

look at the -t switch to change the field terminator.

To get the quoted delimitters is a bit more tricky I think.
Could probably do it with a format file - I usually generate a view to do the bcp from and that puts quotes round the string characters for me.

==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.



Go to Top of Page

nizmaylo
Constraint Violating Yak Guru

258 Posts

Posted - 2002-02-25 : 11:36:21
Let us know if you find it - I do the same thing as NR.

helena
Go to Top of Page
   

- Advertisement -