Remove the lines from the query output

  •  

    On TSQL Command of;

    set nocount on

    select @@version

    Getting the output as;

                                                                                                                                                                                                                                                                    

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Microsoft SQL Server  2000 - 8.00.2039 (Intel X86)

     May  3 2005 23:18:38

     Copyright (c) 1988-2003 Microsoft Corporation

     Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 2)

    How to remove the lines from the output?

     

    Sivaprasad S - [ SIVA ][/url]http://sivasql.blogspot.com/[/url]

  • how about this:

    set nocount on

    select @@version

    select replace(replace(@@version,char(13),''),char(10),'')

    results:

    Microsoft SQL Server  2000 - 8.00.760 (Intel X86)  Dec 17 2002 14:22:05  Copyright (c) 1988-2003 Microsoft Corporation Personal Edition on Windows NT 5.0 (Build 2195: Service Pack 4)

     

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • On any select statement output i want to eliminate the header line as below

    "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- "

    Sivaprasad S - [ SIVA ][/url]http://sivasql.blogspot.com/[/url]

  • Hi,

    Press Ctrl + D before execution of your Query

    and then Run Your Query

    Regards,

    AMIT GUPTA

    MCDBA

  • this is part of the query analyzer: QA automatically puts the column names and a lineof dashes  to separate the data from column names.

    you will not get dashes if you are querying ther data from an applicaiton; it's just a display issue with QA;

    alternatively within QA click control+D and run the query to get results in grid mode. then when you copy/paste, you get just the cell(s) you selected.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • I calling this as batch file using OSQL,  CTRL+D will not be no use.

     

    Sivaprasad S - [ SIVA ][/url]http://sivasql.blogspot.com/[/url]

  • i'm sure you already read the help that is available for osql; as you identified, there is no way to remove the line dashes separator directly with osql ; you can supress the batch numbers(-n param) and the column headers(-h1), but not the line the column headers would occupy, nor the separator line with all the dashes;

    what you can do:

    you would have to send the results to a text file, and start reading the results at line #3, where the data begins, or insert the results into a variable and read all results after the 2nd instance of CrLf.

    you'll need to do that, or get your query results a different way, whether it is from an ADODB.recordset, or from a .net datatable, or whatever; it really depends on your application.

    example:

    c:\test.qry file:

    set nocount on

    select @@version

    command:

    osql /U sa /P  -n -h1 -w 8000 /i c:\test.qry /o c:\results.res

     

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Nice job Lowell,

    Small correction, though... the switch to turn off the header and the dotted line is -h-1 and not just -h1.

     

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • print @@version

    Tim Wilkinson

    "If it doesn't work in practice, you're using the wrong theory"
    - Immanuel Kant

  • Doh!  The simplest answer is usually the best and the most elusive... that'll sure do it, Tim!  Good thinkin'

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • PRINT nly constants, expressions, or variables allowed here. Column names are not permitted.

    How about eliminating the lines on the below query

    OSQL -SwSRVR01 -E -Q"set nocount on  select name from sysobjects" -n

     

    Sivaprasad S - [ SIVA ][/url]http://sivasql.blogspot.com/[/url]

  • you can do this for one value:

    "set nocount on declare @v-2 sysname select top 1 @v-2 = name from sysobjects print @v-2"

    Tim Wilkinson

    "If it doesn't work in practice, you're using the wrong theory"
    - Immanuel Kant

  • Sure... no problem...

    OSQL -SwSRVR01 -E -Q"set nocount on  select name from sysobjects" -n -h-1

     

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply