DECLARE @tempTable TABLE(Id int);

INSERT INTO @tempTable
SELECT Id FROM TestTable WHERE Name='123'; --查询出的记录必须与@tempTable表结构一致

SELECT * FROM @tempTable;

如果要将表变量跟别的表做关联查询,需要给表变量加上别名使用,否则会报"必须定义局部变量(Must declare the scalar variable)"错误。

相关文章:

  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2022-01-18
猜你喜欢
  • 2022-12-23
  • 2021-05-19
  • 2021-12-05
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案