MS SQL Server OSQL - Column format/length

Posted on 2004-11-21
Last Modified: 2008-02-01
MS SQL Server OSQL - I am running a query using osql and returning the resultant output to a file.  

It appears the minimum length of each column returned is 4 characters.  eg Try " SELECT '1' " as the query and it returns 4 characters, ie "1   ".  

Is there any way to to get rid of this apparent 4 character minimum per column?  I am  using the arguments -s -n -h-1 -m-1 -w 145 -b when running the query.
Question by:mgreif
    LVL 8

    Expert Comment


    select cast (1 as int)


    select ltrim(rtrim(1))
    LVL 16

    Accepted Solution

    No there isn't. Sorry for the blunt answer.
    LVL 16

    Expert Comment

    If you want more control over the output format, then consider using DTS rather than osql. You can still run this from the command line using the DTSRUN utility.

    Author Comment

    Thanks, I was sure that was the case since I couldn't find anything on it, but since I am fairly new to MS SqlServer, I wanted to find out!
    LVL 16

    Expert Comment

    Thanks for the revision.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    This is my first ever Article on EE or elsewhere; therefore, please bear with me if I have some discrepancies in my writing. I read many articles and questions related to "how to pass values to SSIS packages at run-time?"  Hence, this common ques…
    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

    733 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

    25 Experts available now in Live!

    Get 1:1 Help Now