Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Scripts
Message
 
À
13/07/2004 11:16:16
John Baird
Coatesville, Pennsylvanie, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Divers
Thread ID:
00920132
Message ID:
00923790
Vues:
28
Your issue:
How do I run a script from within a script?

I have a table update script from which I would like to call other scripts. Is this possible?
If so how? execute fails..

Answer:
Depending how complex your scripts you can create a dynamic sql and execute it.
Example:
DECLARE @sqltext varchar(4000)
set @sqltext = 'UPDATE mytable SET mycolumn = ''XXX'''WHERE updatecondition = ''Z'''

EXECUTE @sqltext

OR (from BOL dynamic SQL statements)
sp_executesql supports the setting of parameter values separately from the Transact-SQL string:

DECLARE @IntVariable INT
DECLARE @SQLString NVARCHAR(500)
DECLARE @ParmDefinition NVARCHAR(500)

/* Build the SQL string once.*/
SET @SQLString =
N'SELECT * FROM pubs.dbo.employee WHERE job_lvl = @level'

SET @ParmDefinition = N'@level tinyint'

/* Execute the string with the first parameter value. */
SET @IntVariable = 35
EXECUTE sp_executesql @SQLString, @ParmDefinition,
@level = @IntVariable

/* Execute the same string with the second parameter value. */
SET @IntVariable = 32
EXECUTE sp_executesql @SQLString, @ParmDefinition,
@level = @IntVariable



If you need to get very complex create a dynamic script via any process to create a text file. see BOL SQLExecute

Finally you can create a DTS package via the same type of processes out lined above and use DTSRUN from a command line or the XP_CMDSHELL

Hope this gives you some suggestions
Software engineers are trained to read and understand code; they are not trained in mind reading. Document the purpose not just the functionality.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform