Я пытаюсь добиться, чтобы столбец ID из @ temp2 соответствовал столбцам как intA, так и intB из @ temp1. Результат конечного результата, который я надеюсь увидеть, будет выглядеть примерно так:
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
спасибо за любую помощь!