我想知道是否可以创建一个将值插入动态表的存储过程.
I was wondering if I can make a stored procedure that insert values into dynamic table.
我试过了
create procedure asd
(@table varchar(10), @id int)
as
begin
insert into @table values (@id)
end
同时将 @table 定义为表变量
also defining @table as table var
感谢您的帮助!
这可能对你有用.
CREATE PROCEDURE asd
(@table nvarchar(10), @id int)
AS
BEGIN
DECLARE @sql nvarchar(max)
SET @sql = 'INSERT INTO ' + @table + ' (id) VALUES (' + CAST(@id AS nvarchar(max)) + ')'
EXEC sp_executesql @sql
END
在此处查看更多信息:http://msdn.microsoft.com/de-de/library/ms188001.aspx
这篇关于将值插入动态表的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
SQL - 过滤器值为空时全选SQL - Select all when filter value is empty(SQL - 过滤器值为空时全选)
如何以及在何处设置 MAXRECURSION 选项?How and where do I set the MAXRECURSION option?(如何以及在何处设置 MAXRECURSION 选项?)
TABLOCKX 与可序列化TABLOCKX versus SERIALIZABLE(TABLOCKX 与可序列化)
TSQL 常量...使用变量还是文字?TSQL Constants... Use Variable or Literal?(TSQL 常量...使用变量还是文字?)
TSQL RIGHT 字符串函数不起作用TSQL RIGHT String function not working(TSQL RIGHT 字符串函数不起作用)
SQL中临时表与物理表的比较速度是多少?What is the comparative speed of temporary tables to physical tables in SQL?(SQL中临时表与物理表的比较速度是多少?)