T-SQL:如何加入@variable 表(另一种尝试) [英] T-SQL: How to join @variable tables (another try)
本文介绍了T-SQL:如何加入@variable 表(另一种尝试)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道,这是这个问题的重复问题.但是我遇到了同样的问题,也许我可以提供更多可用信息.
I know, this is a duplicate question of this question. But i encountered the same problem and maybe i can provide some more available informations.
如果我尝试以下示例查询:
If i try out the following example query:
DECLARE @_Files TABLE (ID INT, Filename VARCHAR(MAX));
DECLARE @_Errors TABLE (ID INT, Label VARCHAR(MAX), Value VARCHAR(MAX));
insert into @_Files
select 73, 'abc'
insert into @_Errors
select 73, 'Some label name', 'Just a value'
select
*
from
@_Errors
inner join @_Files
on @_Errors.ID = @_Files.ID
我收到错误消息:
The @_Errors-scalar variable must be declared.
The @_Files-scalar variable must be declared.
我使用的是 SQL-Server 2008 R2 Express 并且它在兼容性级别 100 下运行.那么我有什么想法为什么会出现这个错误?
I'm using SQL-Server 2008 R2 Express and it is running at compatibility level 100. So any ideas why i get this error?
推荐答案
要么给他们一个别名,然后在 JOIN
中引用,要么使用方括号.下面混合了两种可能性.
Either give them an alias that you then refer to in the JOIN
or use square brackets. The below mixes both possibilities.
SELECT *
FROM @_Errors Errors
INNER JOIN @_Files
ON Errors.ID = [@_Files].ID
这篇关于T-SQL:如何加入@variable 表(另一种尝试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文