|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
USE variable databaseHow can I make an SQL script being executed by SQLCMD to change the
current database context dynamically. The database to use is passed through from the batch file, and therefore dynamic within the script. The script will ultimately create a new database. Example. DECLARE @Database varchar(64); SET @Database = '$(Database)'; IF @Database IS NULL OR RTrim(@Database) = '' SET @Database = 'Testing'; USE @Database; Here is an article that I wrote that explains how to use variables in sqlcmd
scripts. Hopefully this will get you going. If not let me know: http://www.databasejournal.com/features/mssql/article.php/3566401 Show quote "harris***@yahoo.com.au" wrote: > How can I make an SQL script being executed by SQLCMD to change the > current database context dynamically. The database to use is passed > through from the batch file, and therefore dynamic within the script. > The script will ultimately create a new database. > > Example. > > DECLARE @Database varchar(64); > SET @Database = '$(Database)'; > IF @Database IS NULL OR RTrim(@Database) = '' > SET @Database = 'Testing'; > > USE @Database; > > I did try: USE $(Database) but the new [:] commands don't interect very
well within a script, which then causes other issues. For now, I've just gone back to XP command batch files which seem to hang most things together. Until SQLCMD can integrate [:] commands seemlessly into the rest of an SQL script, it's very limiting. Greg Larsen wrote: Show quote > Here is an article that I wrote that explains how to use variables in sqlcmd > scripts. Hopefully this will get you going. If not let me know: > > http://www.databasejournal.com/features/mssql/article.php/3566401 > > "harris***@yahoo.com.au" wrote: I did try: USE $(Database) but the new [:] commands don't interect very
well within a script, which then causes other issues. For now, I've just gone back to XP command batch files which seem to hang most things together. Until SQLCMD can integrate [:] commands seemlessly into the rest of an SQL script, it's very limiting. Greg Larsen wrote: Show quote > Here is an article that I wrote that explains how to use variables in sqlcmd > scripts. Hopefully this will get you going. If not let me know: > > http://www.databasejournal.com/features/mssql/article.php/3566401 > > "harris***@yahoo.com.au" wrote: |
|||||||||||||||||||||||