SQL Server: table variable used in a inner join

前端 未结 5 963
无人及你
无人及你 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:06

    Justin's answer is correct syntactically - you need to assign an alias to the temp table (same for table type variables in 2008).

    However, be aware that neither table variables nor table-type variables have any statistics associated with them, and therefore can lead the query optimiser to make very dubious choices with regard to execution plans (because it will always estimate that the table variable contains 1 row - and therefore usually chooses nested loops as a join operator).

提交回复
热议问题