转发先前用作参考的相同示例代码。
USE <Database>
GO
/* This is a template table */
CREATE TYPE Emp_Details AS TABLE
([Name] VARCHAR(100)
, [Description] VARCHAR(100)
, [Address] VARCHAR(100));
GO
/* The following is your Table Emp_Details which you must be having already*/
CREATE TABLE Emp_Details
([Name] VARCHAR(100)
, [Description] VARCHAR(100)
, [Address] VARCHAR(100));
GO
/* Consider this as your Input Data i.e CSV file or Excel (Note: I have created a table for sample)*/
CREATE TABLE Emp_Details1
([Name] VARCHAR(100)
, [Description] VARCHAR(100)
, [Address] VARCHAR(100));
GO
INSERT INTO Emp_Details1 VALUES ('John','Test','123')
INSERT INTO Emp_Details1 VALUES ('John1','Test1','1234')
INSERT INTO Emp_Details1 VALUES ('John2','Test2','1235')
GO
SELECT * FROM Emp_Details
/* Declare a variable that references the type. So when you reference a `TYPE` it takes the table template which we created previously*/
DECLARE @Emp AS Emp_Details;
/* Add data to the table variable. In your case push the data that you get into the @Emp */
INSERT INTO @Emp ([Name], [Description], [Address])
SELECT [Name], [Description], [Address]
FROM Emp_Details1;
/* Pass the table variable data to a stored procedure. */
EXEC [dbo].[Insert_Deatils] @Emp;
GO
SELECT * FROM Emp_Details
,您声明此表型@InsertAircraft
为什么你会因为如果存在条件 – 2017-06-14 07:14:19
Edited..now检查代码 – Superr
在第一条语句的截断Emp_Details表然后 – 2017-06-14 07:15:49