动态SQL
/*建表*/
create PROCEDURE Add_Ship_sample
(
@table_name nvarchar(50)
)
as
DECLARE @sql nvarchar (4000)--用于构造SQL语句
set @sql='create table '+@table_name+'(id int,type int)'
exec(@sql)
/*出入数据*/
CREATE PROCEDURE InsertSales @uid nvarchar (50), @pwd nvarchar (50),
@eMail nvarchar (50),@tablename nvarchar(50)
AS
DECLARE @InsertString NVARCHAR(500)
/*DECLARE @OrderMonth INT*/
-- Build the INSERT statement.
SET @InsertString = 'INSERT INTO ' +
/* Build the name of the table
SUBSTRING( DATENAME(mm, @PrmOrderDate), 1, 3) +
CAST(DATEPART(yy, @PrmOrderDate) AS CHAR(4) ) +*/
@tablename +
/* Build a VALUES clause. */
' VALUES (@uid, @pwd, @eMail)'
/* Set the value to use for the order month because
functions are not allowed in the sp_executesql parameter
list. */
/*SET @OrderMonth = DATEPART(mm, @PrmOrderDate)*/
EXEC sp_executesql @InsertString,
N'@tablename nvarchar(50),@uid nvarchar (50),@pwd nvarchar (50),@eMail nvarchar (50)',
@tablename,@uid,@pwd,@eMail
GO