2
我想完成的是从@ temp2中获取ID列以对应来自@ temp1的intA和intB列 我希望看到的最终结果输出会看起来像像:需要MS-SQL查询帮助
intA intB 'asset1' 'asset2' 'name1' 'name2'
1 1 108 108 Cash Cash
1 2 108 109 Cash Commodities
1 3 108 138 Cash Stock
.
.
.
2 5 109 111 Commodities Equity
这里是我一起工作的一些样本数据:
declare @temp1 table
(
intA int,
intB int
)
insert @temp1
select 1,1 union all
select 1,2 union all
select 1,3 union all
select 1,4 union all
select 1,5 union all
select 2,1 union all
select 2,2 union all
select 2,3 union all
select 2,4 union all
select 2,5
select * from @temp1
declare @temp2 table
(
oneup int,
id int,
name varchar(30)
)
insert @temp2
select 1,108,'Cash' union all
select 2,109,'Commodities' union all
select 3,138,'Stock' union all
select 4,110,'Bonds' union all
select 5,111,'Equity'
select * from @temp2
select t1.*,t2.* from @temp1 t1
inner join @temp2 t2
on t1.intA = t2.oneup
我不能让参加工作权给我一个输出像我期望的那样。 使用SQL2008
感谢您的任何帮助!
+1包括样本数据。 – 2011-02-15 19:02:09