2017-06-14 73 views
-1

我正試圖用下面的代碼使用BizTalk插入數據到表中。但是我面臨錯誤,因爲「過程或函數Emp_Details指定的參數太多。」執行時發生錯誤表類型參數

有人可以幫我解決這個問題嗎?

ALTER PROCEDURE [dbo].[Emp_Details] 

       (@InsertDetails InsertDetailsType readonly) 
    AS 
    Begin 

    Truncate table [dbo].[Emp_Details] 

      INSERT INTO [dbo].[Emp_Details] 
       (
       [NAME], 
       [DESCRIPTION], 
       [EMPID] 

      ) 
     select 

       [NAME], 
       [DESCRIPTION], 
       [EMPID] 
    from @InsertDetails; 


    Begin 
    if exists(select 1 from [dbo].[Emp_Details]where NAME='Raul') 

    Delete from [Emp_Details]where NAME='Raul' 

    End 

    end 
+0

爲什麼你會因爲如果存在條件 – 2017-06-14 07:14:19

+0

Edited..now檢查代碼 – Superr

+0

在第一條語句的截斷Emp_Details表然後 – 2017-06-14 07:15:49

回答

-1

轉發先前用作參考的相同示例代碼。

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
+0

我不明白這個 – Superr

+0

@Raul在代碼中添加了一些註釋,如果你仍然無法理解它,你能解釋一下代碼的哪一部分。 – Joby

相關問題