osql Help

  • I have created a daily job on SQL Server2000 that uses the osql utility.

    Here is my statement:

    osql -E -S Servername -i d:\query.sql -o d:\output.txt

    Since this runs daily, I want to name the output.txt to yesterday's date so it is unique. (example: 20071014.txt)

    Does anyone have any suggestions on how this can be done?

    Thanks in advance!

  • the convert() function has some special formats when converting date time...the format 112 is what you are looking for:

    declare @cmd varchar(255)

    SELECT CONVERT(VARCHAR,getdate(),112) + '.txt'

    SELECT @cmd='osql -E -S Servername -i d:\query.sql -o d:\' + CONVERT(VARCHAR,getdate(),112) + '.txt'

    print @cmd

    results:

    osql -E -S Servername -i d:\query.sql -o d:\20071015.txt

    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!

  • That worked perfect. Thanks alot!:D

Viewing 3 posts - 1 through 3 (of 3 total)

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