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 |
|
kgundava
Yak Posting Veteran
66 Posts |
Posted - 2011-08-17 : 12:16:38
|
| Hi All, I am running a Except query between 2 tables, where i have to write the out put to a *.txt file(probably formatted).In the txt file i would have to print the column headers as well.Please let me know how can i do it(example Plzz).Is it through BCP or SQLCMD etc....Thanks....... |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-08-17 : 13:12:16
|
You can use SQLCMD and it will write headers by default. For example:sqlcmd -Q "SELECT * FROM AdventureWorks2008R2.Person.Person" -o MyOutput.txt That example is right out of this page: http://msdn.microsoft.com/en-us/library/ms180944.aspx |
 |
|
|
kgundava
Yak Posting Veteran
66 Posts |
Posted - 2011-08-17 : 18:13:14
|
| Thanks Sunita. I Still have one small issue though :(. I am using this below piece to write the data to a CSV.The output includes the rowcount and this screws up the allignment.So i have used set nocount in the cmd and this does not work.Please let me know where i am going wrong.Declare @FILE SYSNAMESELECT @FILE = 'osql -E –S -s“,” -Q"set nocount;select * from RDATAS" -w 7000 -o"E:\ReportNew\TEST.CSV"'EXEC master..XP_cmdshell @FILEThanks.... |
 |
|
|
|
|
|