running SQL commands from .bat file

  • Hi,

     

    Is there a way to execute SQL commands from a .bat file , I need to run SQL querys from windows scheduler

  • Yes, use the OSQL command

    e.g.

    osql -S servername -E -i sql_script.sql -o outputfile.txt

    -S = servername

    -E = Windows authentication (trusted)

    [-U = SQLServer username]

    [-P = SQLServer password]

    -i = SQL commands input file name

    -o = output file name

  • Okay, your question appears to have been answered... so, now let me "enlighten" a bit and see if there is expanded commentary.

    A file with the extension ".bat" is commonly referred to as a "batch file".  This goes back to DOS 1.0 in 1979.  DOS has evolved into other flavors of the OS and we are now at 32 and 64 bit versions.  The 16 bit ended in Windows 98 SE, and of course there is some backwards compatibility still today.

    "Batch files" today, in the newer environments, are done with files that end with ".cmd", still referred to as "batch files" by some, more technically "command files".

    The use and existance of .bat and/or .cmd as a file extension SHOULD indicate whether these are targeted for a 16 bit OS, or newer.  I think that 98SE is still under MS support... not sure about maintenance... but, the point being...

    We have progressed.

    I would like to see more people aware of this... and actually see the change take place; althought I know that I am just being pissy

    David

    Thank-you,
    David Russell
    Any Cloud, Any Database, Oracle since 1982

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

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