CRIIT
asked on
How to write a stored procedure to create a table using a parameter
Hi,
I have a stored procedure, that i want to use to create a table. I want to take in a parameter and use this parameter as the table name.
=========================
CREATE PROC proc1
@myTblName nvarchar(15)
AS
BEGIN
CREATE TABLE [@myTblName] (
[id] [bigint] NOT NULL,
[col1] [nvarchar](50) NULL,
[col2] [int] NULL,
[col3] [nchar](10) NULL,
[col4] [money] NULL,
[col5] [money] NULL,
[col6] [bigint] NULL,)
END
GO
========================== =====
This stored procedure runs, but not take in the parameter. it will only create a table with the name of "@myTblName". can anyone help? thanks
I have a stored procedure, that i want to use to create a table. I want to take in a parameter and use this parameter as the table name.
=========================
CREATE PROC proc1
@myTblName nvarchar(15)
AS
BEGIN
CREATE TABLE [@myTblName] (
[id] [bigint] NOT NULL,
[col1] [nvarchar](50) NULL,
[col2] [int] NULL,
[col3] [nchar](10) NULL,
[col4] [money] NULL,
[col5] [money] NULL,
[col6] [bigint] NULL,)
END
GO
==========================
This stored procedure runs, but not take in the parameter. it will only create a table with the name of "@myTblName". can anyone help? thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER