SQL Server: table variable used in a inner join

前端 未结 5 964
无人及你
无人及你 2021-01-01 12:18

What is the problem with following SQL. Can table variable not be used in JOIN clause?

Error msg is of \"Msg 170, Level 15, State 1, Line 8 Line 8:

5条回答
  •  误落风尘
    2021-01-01 13:03

    Apart from the t1 alias being in the wrong place, nobody else mentioned using square brackets around the table variable, instead of an alias. Changing the update statement to the following will work too:

    UPDATE t1
    SET
        t1.SportName = [@t]._SportName
    FROM
        @t INNER JOIN tblSport t1 ON t1.Lang = [@t]._Lang
    

    [Tested on SQL Server 2005.]

提交回复
热议问题