Home All Groups Group Topic Archive Search About
Author
19 Aug 2005 2:18 PM
Amil
hi all,
how can i call a .sql script from the Query Analyzer?  I know I can open the
script and run it.  I want to test a my code but need to initialize the
tables everytime (which is what the .Sql script is doing) i run it.  so i was
hoping to be able to call the script from within another script, similar to:
exec mystoredproc
go
-- my codes here
go

Author
19 Aug 2005 2:24 PM
Aaron Bertrand [SQL Server MVP]
Have a look at osql in Books Online.  Once you get a working command line
version of your script, use EXEC master..xp_cmdshell 'osql ...'




Show quote
"Amil" <A***@discussions.microsoft.com> wrote in message
news:0140740F-E8A5-4B54-8016-93BA8A508C75@microsoft.com...
> hi all,
> how can i call a .sql script from the Query Analyzer?  I know I can open
> the
> script and run it.  I want to test a my code but need to initialize the
> tables everytime (which is what the .Sql script is doing) i run it.  so i
> was
> hoping to be able to call the script from within another script, similar
> to:
> exec mystoredproc
> go
> -- my codes here
> go
Author
19 Aug 2005 5:25 PM
Amil
thanks. will check it out

Show quote
"Aaron Bertrand [SQL Server MVP]" wrote:

> Have a look at osql in Books Online.  Once you get a working command line
> version of your script, use EXEC master..xp_cmdshell 'osql ...'
>
>
>
>
> "Amil" <A***@discussions.microsoft.com> wrote in message
> news:0140740F-E8A5-4B54-8016-93BA8A508C75@microsoft.com...
> > hi all,
> > how can i call a .sql script from the Query Analyzer?  I know I can open
> > the
> > script and run it.  I want to test a my code but need to initialize the
> > tables everytime (which is what the .Sql script is doing) i run it.  so i
> > was
> > hoping to be able to call the script from within another script, similar
> > to:
> > exec mystoredproc
> > go
> > -- my codes here
> > go
>
>
>
Author
19 Aug 2005 2:26 PM
Anith Sen
One option is to use osql via. xp_cmdshell like:

EXEC master..xp_cmdshell
'osql -S<yourServer> -U<user> -P<password> -iC:\File.sql -n '

where C:\File.sql is your script file in this example. See SQL Server Books
Online for more details and examples of osql & xp_cmdshell.

--
Anith

AddThis Social Bookmark Button