all groups > sql server dts > april 2005 >
You're in the

sql server dts

group:

bcp


bcp Hoosbruin
4/29/2005 6:20:40 PM
sql server dts:

I'm using BCP with queryout and exporting data from a table to a .csv file.
Using this as a template it works fine but is there anyway to get the column
headings along with the data. I'm using this method because I can create
different output filenames. I have a DTS to do this but I can't get Global
Variables to work creating different filenames.

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

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

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

PRINT @bcpCommand


Re: bcp Allan Mitchell
4/30/2005 12:00:00 AM
Can you not use this article to do what you want?

How to manipulate the Execute Process task.
(http://www.sqldts.com/default.aspx?251)

--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.SQLIS.com - SQL Server 2005 Integration Services.
www.Konesans.com


[quoted text, click to view]

Re: bcp Allan Mitchell
4/30/2005 12:00:00 AM
Unfortunately not, AFAIK bcp will not generate the column names for you. There may be something you could do with a view and a
union though.

--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.SQLIS.com - SQL Server 2005 Integration Services.
www.Konesans.com


[quoted text, click to view]

Re: bcp Hoosbruin
4/30/2005 7:51:11 AM
I've tried to get this to work with no luck. Can you give me a few snippets
of code to create multiple output files that each have dynamic names at
execution.

Thanks





[quoted text, click to view]

Re: bcp Hoosbruin
4/30/2005 11:40:38 AM

That would work

much thanks !!!!!!!

Would there be anyway to get COLUMN headings with this scenario...


[quoted text, click to view]

Re: bcp Allan Mitchell
4/30/2005 3:02:44 PM
Would not something like this work.

strCmdLine = "bcp ""SELECT * FROM pubs..authors ORDER BY au_lname"" queryout ""c:\MyFile" +
REPLACE(DTSGlobalVariables("DateVariable").Value,"/","") + ".txt"" - S. -T -c"


--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.SQLIS.com - SQL Server 2005 Integration Services.
www.Konesans.com


[quoted text, click to view]

Re: bcp Hoosbruin
4/30/2005 7:57:28 PM
thanks again...


[quoted text, click to view]

AddThis Social Bookmark Button