How to remove extra space from OSQL output?

  • I want to have 1 line for each row for the output. But the output file from the code below has extra lines in each row. What I am missing here? Any advice?

    declare @cmd varchar(1000)

    select @cmd = 'osql -E -S -h-1 -w 1000 -s ; -Q"select * from pubs.dbo.sysusers" -o"c:\myoutputfile.txt"'

    exec master..xp_cmdshell @cmd

    Thank you!

  • this is an old post, but my poor solution seems to be a follow up DOS script that you can execute via cmdshell.

    type outputfilename.txt | findstr -i [highlight="#987654"]commonString[/highlight] >2.txt

    Fortunately, in my situation, I do have a string that always occurs, in my case the server name %COMPUTERNAME% or @@SERVERNAME.

  • Since the -s parameter defaults to a space, you need to (IIRC) explicity say -s"" (dash s followed by two double quotes with no spaces in between).

    --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 3 posts - 1 through 2 (of 2 total)

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