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 |
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2013-02-22 : 03:36:28
|
how can i add in the file name together with the date?TableName_20130221Below query seems not working: declare @Date varchar(max),@path varchar(max) set @Date = replace(convert(varchar, getdate()-1,111),'/','')EXEC master..xp_cmdshell'bcp "select * from ##A" queryout "\\...\TableName_+''@Date''.txt" -c -t"|" -T -S' |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-02-22 : 04:36:58
|
declare @sql varchar(4000)declare @Date varchar(max)set @Date = replace(convert(varchar, getdate()-1,111),'/','')set @sql = 'bcp "SELECT * FROM DBNAME.dbo.TableNAme" queryout "D:\temp\'+ @date +'.txt" -c -t"|" -T -S' EXEC master..xp_cmdshell @sql--Chandu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-23 : 03:29:59
|
also to run this you need to have xp_cmdshell enabledEXEC sp_configure 'show advanced options', 1GORECONFIGUREGOEXEC sp_configure 'xp_cmdshell' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2013-02-24 : 05:40:49
|
Thanks!Is working fine now..How can I add in the column name above?FirstName|LastName|MiddleNameMary|Ann|JosephHenry|John|Johnson |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-02-24 : 08:15:57
|
BCP does not have an option that lets you specify that column headers be included in the output. There are workarounds that people use such as creating a view that includes the header etc., that you will find if you google for it. None of those are really clean solutions though. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|