Run File From Query Analyzer?

  • Hi,

    Is there a way to open and run a file from within Query Analyzer?

    In Oracle, using SQL*Plus, the command is:

    SQL>run 'c:\myscript.sql' -- to open and run; no display

    or

    SQL>open 'c:\myscript.sql' -- to open; contents are displyed from file

    SQL>/ -- to run what is on screen

    Many thanks. Jeff

    Many thanks. Jeff

  • Use isql /U <Login_ID> /P <Pwd> /i <Query_FileName.qry>

    Shas3

  • You can use the isqlw utility from within Query Analyzer.

    isqlw -d pubs -E -f "c:\Program Files\Microsoft SQL Server\MSSQL\Install\instpubs.sql"

    All the best,

    Dale

  • If you just mean manually grabbing a file and running it: File | Open.

    Then F5 to run what is displayed.

    Otherwise you'll have to go to the command line like the others have posted.

    K. Brian Kelley

    http://www.truthsolutions.com/

    Author: Start to Finish Guide to SQL Server Performance Monitoring

    http://www.netimpress.com/shop/product.asp?ProductID=NI-SQL1

    K. Brian Kelley
    @kbriankelley

  • You can also customize the toolbar to run applications like Notepad. I did this for Textpad. Didn't mention this before 'cause I didn't think that was what you were looking for.

    From MSDN:

    To add commands to the Tools menu

    1. On the Tools menu, click Customize.

    2. In the Customize dialog box, click the Tools tab.

    3. Click the add button. In the Menu contents list, type the name to appear on the Tools menu. This might be the name of an executable or the name of a document to be opened. Use the up and down arrows to position the name in the menu.

    4. In the Command box, enter the name and location of the file to be executed. You can use the browse (...) button to find the directory in which it resides.

    For example, to execute osql, enter this:

    C:\Program Files\Microsoft SQL Server\80\Tools\Binn\osql.exe

    If using Microsoft® Windows NT® and want to specify Notepad, enter this:

    C:\WINNT\Notepad.exe

    5. Enter any arguments for the command in the Arguments box. For example, if the command is osql, you might specify the options –Usa -Psapassword.

    If the command is Notepad and you want the menu command to invoke a new document, leave this box blank. If you want to open a specific document in Notepad, specify the name of the document here.

    6. In the Initial Directory box, enter the location from which the command will be executed.

    All the best,

    Dale

  • Here the simple way to run or open any OS files from QA:

    exec xp_cmdshell 'C:\Reboot.bat' or

    exec xp_cmdshell 'type C:\Boot.ini'

  • Many thanks to all.

    Jeff

    Many thanks. Jeff

  • From BOL:

    When using isql interactively, you can read an operating-system file into the command buffer with :r file_name. Do not include a command terminator in the file; enter the terminator interactively after you have finished editing.

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

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