更新sql中的多个记录 - 语法

时间:2014-10-22 05:28:08

标签: sql tsql sql-server-2012

尝试更新多条记录。

tbl_test - 现有表格

EmployeeName Effort  Date
aaa            8     2014-10-21
bbb            9     2014-10-21
ccc            7     2014-10-21

@dtCSV - 表格类型为参数

EmployeeName Effort
aaa           10    
ccc           10

预期输出:

EmployeeName Effort  Date
aaa           10     2014-10-21
bbb            9     2014-10-21
ccc           10     2014-10-21

此代码在't'附近发出错误 - 语法不正确。执行此操作的正确语法是什么。

ALTER PROCEDURE SaveEffort
( 
    @TimesheetDate datetime, //(2014-10-21)
    @dtCSV AS dbo.SaveEffort_TableType readonly
)
AS
BEGIN
    UPDATE tbl_test t
        SET t.Effort = d.Effort
    FROM @dtCSV d
    WHERE t.EmployeeName = d.EmployeeName
          AND t.[Date] = @TimesheetDate 
END

1 个答案:

答案 0 :(得分:2)

 UPDATE t
 SET t.Effort = d.Effort
 FROM tbl_test t JOIN @dtCSV d
 ON t.EmployeeName = d.EmployeeName
 WHERE t.[Date] = @TimesheetDate