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)
 suppress headings on results of select statement

Author  Topic 

Maquis
Starting Member

25 Posts

Posted - 2003-11-13 : 12:40:05
How do you suppress the headings on the output of a select statement? In Oracle there is a "set heading off" switch...is there something similar in MS SQL?
Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-11-13 : 12:43:43
I do not know if there is a SET command for this; I couldn't find one in BOL. But you can turn off headers in Query Analyzer by going to Tools, Options, then to Results tab. Uncheck print column headers box.

Tara
Go to Top of Page

Maquis
Starting Member

25 Posts

Posted - 2003-11-13 : 12:47:27
Well, that works for QA, but what I'm actually trying to do is dynamically build a select query and send the output to a file, but I want no headings...
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-11-13 : 12:49:57
Then use bcp or DTS for this. Both will allow the option to not have the headings in the file.

Tara
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-11-13 : 12:59:10
BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...BCP...

seemed to have gotten carried away...

Also, if you put your reesult pain in grid mode and save it, you won't get any headers...in a csv file...

But if what you're doing is so manual...why not cut out the heading

(You know Oracle, don't you...)

If one were to but read...it would be obvious....





Brett

8-)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-11-13 : 13:19:25
Try this...


USE Northwind
GO

DECLARE @Cmd varchar(8000), @Uid varchar(10), @Pid varchar(10), @tbName sysname

SELECT @tbname = 'Orders', @Uid = 'sa', @Pid = 'xxx'

SELECT @cmd = 'bcp '+db_Name() + '..' + @tbName + ' out ' + db_Name() + '_' + @tbName + '.csv -c -S'+@@SERVERNAME+' -U'+@Uid+' -P'+@Pid

SELECT @cmd

EXEC master..xp_cmdshell @cmd


Just need to change the password...



Brett

8-)
Go to Top of Page

Maquis
Starting Member

25 Posts

Posted - 2003-11-13 : 15:58:36
OK, I haven't used bcp much, I want to throw the output of 2 different select statements into the same file (actually just throw a trailer record into the file). I tried to use bcp twice, and it appears to overwrite the first, instead of adding the 2nd select output to the end. And no, I can't use a union because the 2 selects have different numbers of expressions. Thanks again.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-11-13 : 16:27:49
You could put the results into two files, then run this to concatenate them:

type *.txt > C:\Temp\Concatfile.txt

You could use xp_cmdshell to do the above command so that you stay within SQL Server.

Tara
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-11-13 : 17:54:32
Good one Tara! I didn't think of that one. Very clever ! (and a nice old-fashioned use of DOS features!)

- Jeff
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-11-14 : 15:33:18
That's why she's the princess!

Command line junkies...unite



Brett

8-)
Go to Top of Page

Sitka
Aged Yak Warrior

571 Posts

Posted - 2003-11-14 : 18:31:30
I don't know how many of you got vs.net early downloads but it was three files (CD size) that had to be built into one exe
great fun using copy append feature to do it for a result of 1.5 GIG file. Now where did I put that hard drive space?
Go to Top of Page
   

- Advertisement -