sql server - TSQL - Merge two tables -


i have following task: have 2 single column tables in procedure , both of them have same amount of rows. i'd "merge" them resulting table 2 columns. there easy way this?

in worst case try add primary key , use insert ... select join requires quite big changes in code have decided ask guys.

just explain answer below, here's example. have following tables:

tablea col1 ---- 1 2 3 4  tableb col2 ---- b c d  resulting table: col1 | col2 1    | 2    | b 3    | c 4    | d 

you can this:

select t1.col1, t2.col1 col2 newtable (    select col1, row_number() over(order (select 1)) rn    table1 ) t1 inner join (    select col1, row_number() over(order (select 1)) rn    table2 ) t2 on t1.rn = t2.rn 

this create brand new table newtable 2 columns 2 tables:

| col1 | col2 | --------------- |    1 |    | |    2 |    b | |    3 |    c | |    4 |    d | 

see in action here:


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -