May 13, 2003 at 11:33 pm
I need to execute a dynamic command against different DBs.
So for normal stuff I'd
USE DB1
COMMAND
But I need to do this within and EXEC ??
Any ideas.
KlK, MCSE
KlK
May 13, 2003 at 11:44 pm
Can also do a
Select * from Database..Table Where
May 14, 2003 at 7:20 am
Unfortunately what I am trying to EXEC is basically a CREATE .... or Alter ...
I thought I had seen this somewhere ??
KlK, MCSE
KlK
May 14, 2003 at 7:41 am
You can do what you want by building dynamic sql that builds dynamic sql, that then gets executed. Here is an example that issues a USE statement, followed by an alter table:
declare @CMD char(1000)
set @CMD = 'use test ' + char(13) + 'declare @cmd char(1000)' + char(13) +
'set @cmd = ''alter table test_it add col_a int''' + char (13) +
'exec (@cmd)'
print @cmd
exec (@cmd)
Gregory Larsen, DBA
If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples
Gregory A. Larsen, MVP
May 14, 2003 at 9:52 am
Thanks Greg, a slight variation of what you provided, solved it perfectly.
KlK, MCSE
KlK
Viewing 5 posts - 1 through 4 (of 4 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