How do I customize the header using OSQL

Posted on 2007-07-23
Last Modified: 2011-10-03
I have a DOS batch job that runs an OSQL command.

osql -dION_Data -E -ieaf8.sql -l -n -oeaf8.txt -s"      " -SMAPOW\ION -w500

If I use the -h-1 parameter, I see just the data:
23-Jul-2007 11:11:11.00<TAB>1.0<TAB>22.2222<TAB>&
23-Jul-2007 11:11:12.00<TAB>1.0<TAB>22.2222<TAB>&
23-Jul-2007 11:11:13.00<TAB>1.0<TAB>22.2222<TAB>&

If I omit the parameter, I see the column name and a line of hyphens:
23-Jul-2007 11:11:11.00<TAB>1.0<TAB>22.2222<TAB>&
23-Jul-2007 11:11:12.00<TAB>1.0<TAB>22.2222<TAB>&
23-Jul-2007 11:11:13.00<TAB>1.0<TAB>22.2222<TAB>&

Is there a way to keep the column names and suppress the 2nd line (the hyphens)?
If not, I need to suppress the header (-h-1) and manually output the column names (tab delimited).  How can I do this from my SQL input file?
Question by:sainiak
    LVL 3

    Accepted Solution

    suppress the header and construct your query like this.

    select 'col1', 'col2'
    union all
    select col1, col2
    from yourtable

    If you want to use an order by you need to include the column in the header line as well

    Author Comment

    I had to add a few converts to the 2nd query, and then it worked.  I am no SQL expert, but I think this is because the datatypes must be the same in both queries.  Thanks!

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now