SQL查询SELECT FROM [来自另一个表的列的值] [英] SQL query SELECT FROM [value from column of another table]

查看:481
本文介绍了SQL查询SELECT FROM [来自另一个表的列的值]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表X,当对某些表进行更改时,触发器将在其中插入一行.我已将表名称插入到表X中.

I have a table X where a trigger will insert a row when there's a changes to some tables. I've inserted the table name into table X.

现在,我想用实际的表本身从表X中获取数据,而将inner join从表X中获取.是否可以通过将选择表的列中的值用作内部联接表?

Now, I would like to select the data from table X while inner join with the actual table itself. Is it possible by using a value from a column of the select table as the table for inner join?

查询应该看起来像这样

SELECT X.a, Y.b, Y.c FROM X
INNER JOIN [X.TableName] AS Y ON Y.ID = X.ID

推荐答案

执行

select 'SELECT X.a, Y.b, Y.c FROM X
INNER JOIN [' + X.TableName + '] AS Y ON X.ID = Y.ID 
where x.primarykey =' + x.primarykey from x

将输出一系列sql语句,例如

Will output a series of sql statements like

SELECT X.a, Y.b, Y.c FROM X
INNER JOIN [ customer ] AS Y ON X.ID = Y.ID
where x.primarykey = 1234

如果可以的话,您可以执行"sql to build sql".

that you can then execute "sql to build sql" if you will.

这篇关于SQL查询SELECT FROM [来自另一个表的列的值]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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