表tblEffort
有3列EmployeeName,Effort,Date。我从表类型参数中获取前2列值,并且必须为所有这些值插入公共日期。
以下代码给出错误 - 必须声明表变量" @ TimesheetDate"
CREATE TYPE dbo.SaveEffort_TableType AS TABLE
(
EmployeeName varchar(200),
Effort decimal(18,2)
);
GO
CREATE PROCEDURE SaveEmployeeEffort
(
@TimesheetDate datetime,
@dtCSV AS dbo.SaveEffort_TableType readonly
)
AS
BEGIN
INSERT INTO tblEffort(EmployeeName,Effort,[Date])
SELECT * FROM @dtCSV,@TimesheetDate
END
答案 0 :(得分:1)
您需要将变量放入SELECT
子句,而不是FROM
子句
CREATE PROCEDURE SaveEmployeeEffort
(
@TimesheetDate datetime,
@dtCSV AS dbo.SaveEffort_TableType readonly
)
AS
BEGIN
INSERT INTO tblEffort(EmployeeName,Effort,[Date])
SELECT EmployeeName,Effort, @TimesheetDate FROM @dtCSV
END