Kimberly Woody
Newbie
Points: 2
More actions
April 26, 2006 at 11:41 am
#90895
Is it possible to use CREATE TABLE and use a variable to fill the table name?
For example,
USE somedatabase CREAT TABLE [schema].[@tbname]
Any help would be greatly appreciated!
Pam Brisjar
SSChampion
Points: 12094
April 26, 2006 at 11:51 am
#634390
Sure, just stuff the SQL into a varchar variable, then run exec SQL. See here:
http://msdn2.microsoft.com/en-us/library/ms188332(SQL.90).aspx
so the above would look something like:
USE somedatabase
Declare @sqlstr varchar(250)
set @sqlstr = 'CREATE TABLE [schema].['+@tbname+']'
exec (@sqlstr)
April 26, 2006 at 11:54 am
#634391
Thanks Pam! You ROCK!! It worked terrific!
Ninja's_RGR'us
SSC Guru
Points: 294069
April 27, 2006 at 6:09 am
#634537
Why exactly do you want to be able to do this?
I rarely see the need (valid) for this in a production environement.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply