我使用存储过程导入XML(经过一些检查)。 (SP)
我想为每个导入创建一个新表,该SP有效,但是当我将表名传递给下面的代码时,我得到错误:
USE [DB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spAddNewDataToHoldingTable]
@sUPRN varchar(510),
@sTablename varchar(50)
AS
BEGIN
---------------------------------------
INSERT INTO @sTablename
(
[UPRN]
)
VALUES
(
@sUPRN
)
---------------------------------------
END
尝试:
制作@sTablename - > DECLARE @sTablename var(50)
之前一定要问过但搜索SO / Google但可能是错误的问题?
{{1}}
答案 0 :(得分:1)
试试这可能对你有帮助。
USE [DB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spAddNewDataToHoldingTable]
@sUPRN varchar(510),
@sTablename varchar(50)
AS
BEGIN
---------------------------------------
DECLARE @sTablename_ TABLE (UPRN varchar(510))
INSERT INTO @sTablename_
(
[UPRN]
)
VALUES
(
@sUPRN
)
---------------------------------------
END
注意:在此ive中声明'@sTablename_'作为表变量,它与您的过程输入变量不同