Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use "Create Table" Dynamically ? 2

Status
Not open for further replies.

sa5cha

Programmer
May 29, 2001
34
DE
Hi,

I have the following Problem:

I want to write a stored Procedure which dynamically creates tables on different SQLDatabases and/or Servers.

The following doesn't work:

assumed that the procedure has been called whith this parameter:
Code:
CC_CreateTableMC 'server1.dbo.table1'

The Stored Procedure looks like this:
Code:
CREATE PROCEDURE CC_CreateTableMC
@ServerLocationString varchar
AS
CREATE TABLE  @ServerLocationString (field1 varchar(100))
RETURN

Can anyone help ?

Thank you in advance
Sascha
 
your have to make a string and then execute it.
say u declare:

varchar @strSql(200)--length is as you think should be
set @strSql='Create Table ' + @ServerLocationString +'(field1 varchar(100))'
execute(@strSql)

N.B. thus u can execute any dynamic SQL
 
CREATE PROCEDURE CC_CreateTableMC
@ServerLocationString varchar
AS
begin
declare @xxx varchar(200)
set @xxx=
'CREATE TABLE ' + @ServerLocationString + ' (field1 varchar(100))'
execute(@xxx)
end John Fill
1c.bmp


ivfmd@mail.md
 
Thank you guljar and John Fill for that fast response.

It works fine! :)
It solved a lot of problems for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top