I want to create a table from a stored procedure where the name is passed to it:
I have this:
************************************************** ********
CREATE PROCEDURE sp_TP_CreateTable
(
@TABLENAME as varchar
)
AS
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[@TABLENAME]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[@TABLENAME]
CREATE TABLE [dbo].[@TABLENAME] (
[Description] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Catalog Version] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Mailed] [float] NULL ,
[Sales] [money] NULL ,
[Production $] [int] NOT NULL ,
[Orders] [float] NULL ,
[Response] [float] NULL ,
[Response of Test Control] [int] NOT NULL ,
[Average Invoice] [float] NULL ,
[SMP] [float] NULL ,
[SMP of Test Control] [int] NOT NULL ,
[Catalog Title] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Brand] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Drop Date] [smalldatetime] NULL
) ON [PRIMARY]
GO
But it's createing a table called @TABLENAME How can I get this to work?
Thanks,
Ken