PDA

Click to See Complete Forum and Search --> : SQL Server stored procedures


msdnexpert
Nov 15th, 2000, 04:08 AM
Dear All,
I would like to execute a DDL statement(create table) in an SQL server stored procedure. I am formulating the DDL statement in the stored procedure and is saved in a variable of type varchar. How do I execute that DDL statement.
Thanks in advance

Lafor
Nov 15th, 2000, 04:32 PM
Just a quick example
...
create proc sp_AdhWmCreateRXCRTables with recompile as
begin

declare @command varchar(60)
declare @usename varchar(60)

set nocount on

select @usename = "tblmsdnexpert"
if OBJECT_ID(@usename) is not null
begin
select @command = 'DROP TABLE ' + @usename
exec (@command)
end

select @command = 'CREATE TABLE(......etc"

exec (@command) should do it...

I hope I understood your question correctly..