Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Can I execute a sql script from other sql script?

Author  Topic 

cajina
Starting Member

15 Posts

Posted - 2008-01-03 : 17:52:22


How can I execute a sql script from other sql script?
I used to call scripts from other scripts by using Oracle but I don't know if I can do this in SqlSever!

I need anybody to help, please!



tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-01-03 : 17:53:42
You can use osql/sqlcmd to execute scripts via the command prompt. You can wrap them into batch files. You can also call these via xp_cmdshell if you have the permissions and the config setup (2005).

Let us know more specifically what you mean and we'll be able to better direct you to the answer.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-01-03 : 19:35:06
Why don't you explain what you are trying to do?

I'm sure we can figure something out


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2008-01-08 : 04:05:29
Yes, for example : EXEC master..xp_cmdshell 'osql -S MyServer -U sa -P -ic:\myScript.sql'
(this script is on my c:


Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2008-01-08 : 06:15:56
it is better create a batch file with all the required script files paths. then at the run time, you can provide the server name,database name.(as TKIZER said)

Vinod
Even you learn 1%, Learn it with 100% confidence.
Go to Top of Page

cajina
Starting Member

15 Posts

Posted - 2008-01-08 : 10:26:10
I realy don't remember but for example in Oracle I used to write something like this:

prompt @script2.sql

and it was written into the script1.sql


Go to Top of Page
   

- Advertisement -