Reputation: 1024
I import XML (after some checks) with a stored procedure. (SP)
I want to create a new table for each import, that SP works however when I pass the tables name into the below code I get error:
Must declare the table variable "@sTablename".
Tried:
Making @sTablename --> DECLARE @sTablename var(50)
It must of been asked before but searched SO/Google but probably with the wrong question?
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
Upvotes: 0
Views: 30
Reputation: 901
Try this it may help you.
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
Note: in this ive declared '@sTablename_' as the table variable which is different from your procedure input variable
Upvotes: 1