T-SQL:如何加入@variable 表 [英] T-SQL: How to join @variable tables

查看:30
本文介绍了T-SQL:如何加入@variable 表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
T-SQL:如何加入@variable 表(另一种尝试)

首先:我使用的是 SQL Server 2008.在涉及大量数据的复杂算法中,我一直在使用创建中间表变量的技术:

First: I'm using SQL Server 2008. In a complex algorithm that involves a lot of data, I have been using a technical of creating intermediate table variables:

DECLARE @table AS TABLE (Col1 INT, Col2 VARCHAR(100))

不幸的是,SQL Server 不支持 JOINning @variable 表,它只允许连接数据库中的真实"表.

Unfortunately, SQL Server does not support JOINning @variable tables, it is only allowed to join "true" tables, those in the database.

我可以进行手动"连接,例如

I could do the "manual" join, like

FROM @table1 t1, @table2 t2
WHERE t1.Id = t2.Id

这会导致 INNER JOIN,但这对我来说是错误的.问题是:如何FULL JOIN两个@variable表?

This results in a INNER JOIN, but this is wrong for me. The question is: How do FULL JOIN two @variable tables?

推荐答案

SQL 不支持连接表变量是什么意思?

What do you mean by SQL doesn't support Joining table variables?

它对我有用

DECLARE @table1 AS TABLE (Col1 INT, Col2 VARCHAR(100))
DECLARE @table2 AS TABLE (Col1 INT, Col2 VARCHAR(100))

SELECT *
FROM @table1 t1
FULL JOIN @table2 t2 on t1.Col1 = t2.Col1

这篇关于T-SQL:如何加入@variable 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆