I am using SQL2000 and I would like to join two table together based on their positions
For example consider the following 2 tables:
table1 ------- name -
would be best to use row_number(), but that is only for 2005 and 2008, this should work for 2000...
Try this:
create table table1 (name varchar(30))
insert into table1 (name) values ('cat')
insert into table1 (name) values ('dog')
insert into table1 (name) values ('mouse')
create table table2 (cost int)
insert into table2 (cost) values (23)
insert into table2 (cost) values (13)
insert into table2 (cost) values (25)
Select IDENTITY(int,1,1) AS RowNumber
, Name
INTO #Temp1
from table1
Select IDENTITY(int,1,1) AS RowNumber
, Cost
INTO #Temp2
from table2
select * from #Temp1
select * from #Temp2
SELECT
t1.Name, t2.Cost
FROM #Temp1 t1
LEFT OUTER JOIN #Temp2 t2 ON t1.RowNumber=t2.RowNumber
ORDER BY t1.RowNumber