select identity(int,1,1),[id] into #t from (select EmployeeID as [id] from Employees union select OrderID as [id] from Orders ) aselect * from #t drop table #t
create table #t (type identity(1,1) int, iid int) insert #t select EmployeeID from Employees union select OrderID from Orders select * from #tdrop table #t
你的要求就是跟SQL查询分析器里查出的记录集前方它自己显示的序号吧基于性能考虑,建议采用临时表处理 SELECT IDENTITY(INT, 1, 1) AS Rank,a.ID INTO #tmp FROM (select EmployeeID as ID from Employees union select OrderID as ID from Orders) a SELECT * FROM #tmp用完后DROP TABLE #tmp
insert #t
select EmployeeID from Employees union select OrderID from Orders select * from #tdrop table #t
SELECT IDENTITY(INT, 1, 1) AS Rank,a.ID
INTO #tmp
FROM (select EmployeeID as ID from Employees union select OrderID as ID from Orders) a
SELECT * FROM #tmp用完后DROP TABLE #tmp