March 14, 2003 at 3:10 pm
Is there any way to call a T-SQL script from within a T-SQL script?
March 15, 2003 at 2:01 am
You can use xp_cmdshell to run isql with the script. Don't really see why you would need that though, are you sure that is the right way of doing what you need?
--
Chris Hedgate @ Apptus Technologies (http://www.apptus.se)
March 17, 2003 at 6:30 am
quote:
You can use xp_cmdshell to run isql with the script. Don't really see why you would need that though, are you sure that is the right way of doing what you need?--
Chris Hedgate @ Apptus Technologies (http://www.apptus.se)
March 17, 2003 at 7:15 am
Thank's for the reply and I am familiar with calling the command procedure running the script in batch.
Perhaps there is a better way? We have templates defined to create a database and then scripts to create tables, procedures, views, triggers, etc. I am trying to create a script that would call each of these "sub scripts" rather than combine them all into one big script.
March 17, 2003 at 7:42 am
To my knowledge there is no way to do this in T-SQL. I think Oracle has some syntax for it, that may be why some want this. I can't see any reason to include it in T-SQL. If anything, there could be some way to set it up in Query Analyzer 'automatically'. What you can do is create a command-line batch script that uses osql to run each script.
--
Chris Hedgate @ Apptus Technologies (http://www.apptus.se)
March 17, 2003 at 9:21 am
I would actually suggest using VBScript or JScript via WSH to execute your
scripts. I used to do something similar to what you are talking about with batch
files, but the scripting languages provide so much more capabilities I rarely go
back to dos batch mode. Also with WSH 5.6 there is remote scripting, so that you
can run scripts remotely on other computers. I have written a script that lets
me remotely re-register my com plus objects on my middle tier server. I copy
them over then kick this script off remotely. There are other options : VNC,
Term Serve, Telnet, SSH, etc...., but I like this one as it does not even
require me to have the scripts I am running on the target server. Lets me do
some very inventive administrative work from my desk. And as I am lazy, that is
a good thing. I work really hard so I can take it easy...
Tim C.
//Will write code for food
Tim C //Will code for food
March 17, 2003 at 10:33 am
That sounds like a great solution, and yes, WSH is probably better than batch script. Just me that's oldfashioned.
But still, neither of these solutions makes it possible to call a T-SQL script from within a T-SQL script. But as I said, I don't really see any reason to do that.
--
Chris Hedgate @ Apptus Technologies (http://www.apptus.se)
March 17, 2003 at 10:53 am
Your right, without using xp_cmdshell I don't see another way either. I was trying to offer him an alternative. I really did not understand the need to have it run from TSQL to begin with either. He could use WSH to kick off i/osql, and capture the StdOut from it running.
Tim C.
//Will write code for food
Tim C //Will code for food
March 20, 2003 at 9:45 am
Yes, You can. Make your scripts into store procedure then be called by your command T-SQL script. If this would work for you ?
March 20, 2003 at 8:35 pm
eugene I think he was referring to being able to call .sql file(s) from within T-SQL file if I am not mistaken. Which is better left to batch files or script files.
Tim C.
//Will write code for food
Tim C //Will code for food
Viewing 10 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy