OSQL echoing to outputfile

  • Is there is a way in a sql script to "echo" out lines to an output file?

    We are running several sql scripts using OSQL from a Wise installation script and need to "show" progress by echoing out steps into the log file.

    I am using the -o parameter to echo results of the script but all I get is:

    (52 rows affected)

    (52 rows affected)

    (4 rows affected)

    (1 row affected)

    like that in the log file.

    I'd like something like this:

    updating table xyz:

    (52 rows affected)

    updating table abc:

    (52 rows affected)

    updating table ghi:

    (4 rows affected)

    updating table opq:

    (1 row affected)

    This way, I will know where I am in the script when it "craps out"...

     

  • This works and is pretty nice. I though about using it but wasn't sure it would work right.

    PRINT "Updating DB_Update_Num to 61"

  • The simplest way to accomplish this is by using the -o argument. 

    When using osql -ofilename creates a file that contains all the output.

  • I know that, that's what we're using. I just wanted to insert extra things into the output file kind of like progress desscriptions.

  • Yes, I sorry.  I didn't read it very closely the first time.

    You can add a comment in the output file by adding a select statement in the sql script. (e.g.)

    select "Updateing table a"

    go

     

  • We have decided to use: PRINT 'Updating DB_Update_Num to 61'

    instead of the select you are showing.

  • Mr B... PRINT is exactly what you are looking for... if you don't want the rowcounts to show up in "standard" format, you can do a SET NOCOUNT ON and format @@ROWCOUNT for a nicer output.  Add couple of dashed lines by doing a PRINT REPLICATE(-,78) and your -o logging will look great and be really easy to read.

    --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)

  • Thanks a lot, Jeff, that is just what I needed.

Viewing 8 posts - 1 through 7 (of 7 total)

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