当前位置: 代码迷 >> Sql Server >> 求一条SQl语句,如何把一个表的数据作取出作为字段在另一个表中取值
  详细解决方案

求一条SQl语句,如何把一个表的数据作取出作为字段在另一个表中取值

热度:54   发布时间:2016-04-27 20:59:42.0
求一条SQl语句,怎么把一个表的数据作取出作为字段在另一个表中取值
如题
select   DecNo   from   A  
怎么把DecNo   的值作为字段在B表中取值呢,求一条语句,谢谢各位

------解决方案--------------------
declare @a varchar(1000)
set @a= 'select '
select @[email protected]+DecNo from A
select @a=left(@a,len(@a)-1)
exec(@a+ ' from B ')
------解决方案--------------------
create table a(id int,DecNo varchar(10))
insert a
select 1, 'A1 ' union all
select 2, 'B1 ' union all
select 3, 'C1 '

declare @a varchar(1000)
select @a= ' '
select @[email protected]+ ', '+DecNo from A
select @a=stuff(@a,1,1, ' ')
select 'select '[email protected]+ ' from B '
exec( 'select '[email protected]+ ' from B ')
  相关解决方案