views:

33

answers:

3

Like the title says, in oracle you can issue the following command in SQL*Plus:

SQL> select something from anothertable; #sql
SQL> @{/home/me/somescript.sql};         #load sql from file and execute it
SQL> do something else in script;        #other sql

Without having to file->open the sql script to load it to the UI.

Is there an equivalent in SQL Server Query Manager? I've stumbled upon many situation where i could have used it but i couldn't be able to find a way to accomplish it.

regards

+4  A: 
John Sansom
Thanks for your hint.what i want to achieve is referencing a script from another script. Scenario is a migration and i have to reference several scripts from sql, whether it is SQL Management Studio or isql, doesn't matter. But i dont know if there's a way to accomplish it the SQL*Plus way.
ovm
With the -i switch i would have to switch focus from ISQL back to CMD and issue another ISQL -i file.sql command.
ovm
xp_cmdshell will launch the shell relative to the server, not relative to where ovm is nescessarily running the batch.
Shannon Severance
+1  A: 

Use isql utility http://msdn.microsoft.com/en-us/library/aa214007(SQL.80).aspx

issql ... -iinputfile

Michael Pakhantsov
Thank you, too. please see above comments.
ovm
+1  A: 

If using latter versions of SQL Server (2005 & 2008), see if the :r command in SQLCMD works for you:

:r <filename> Parses additional Transact-SQL statements and sqlcmd commands from the file specified by <filename> into the statement cache. If the file contains Transact-SQL statements that arenot followed by GO, you must enter GO on the line that follows :r. From sqlcmd Utility

Shannon Severance
Thank you Shannon, it's a pity that it is not possible to use that command in the Query Analyzer / Management Studio. But when combining the SQLCMDs -i switch with a script containing :r commands, that would be what i was looking for.
ovm
edit: Ok, it is possible to include and execute a script directly from within the SQLcmd shell, but you cannot build scripts that reference other scripts, the oracle way. When including a :r in a sql script file and load that file into SQLCMD it does not recognize the :r commands and fails executing.
ovm