select * into #temp from DBNOTICE where m_UserID = 'lsnow' ORDER BY m_DocName DESC
select identity(int,1,1) as id ,m_OMID,m_DocName into #TempTable from #temp
select * from #TempTable where id=..
drop table #TempTable
drop table #temp
select identity(int,1,1) as id ,m_OMID,m_DocName into #TempTable from #temp
select * from #TempTable where id=..
drop table #TempTable
drop table #temp
(Select m_OMID,m_DocName DBNOTICE where m_UserID = 'lsnow' ORDER BY m_DocName DESC)tmp
USE PUBS
GO
select identity(int, 1,1) as id,fname into #temp from employee order by fname
select * from #temp
id fname
----------- --------------------
1 Anabela
2 Ann
3 Annette
4 Aria
5 Carine
6 Carlos
7 Daniel
8 Diego
9 Elizabeth
10 Francisco
goselect identity(int,1,1) id, phone,au_lname into #aaa from authors where city like '%a%' order by phone desc这是一个例子,没问题的,是按PHONE字段排序后再放入临时表的
没问题的。
id phone au_lname
---------------------------------------
1 913 843-0462 Smith
2 801 826-0752 Ringer
3 801 826-0752 Ringer
4 707 448-4982 McBadden
5 615 996-8275 del Castillo
6 615 297-2723 Greene
7 503 745-6402 Blotchet-Halls
8 415 986-7020 Green
9 415 935-4228 Yokomoto
10 415 843-2991 Stringer
11 415 836-7128 Hunter
12 415 836-7128 Dull
13 415 834-2919 Straight
14 415 585-4620 Locksley
15 415 534-9219 Karsen
16 415 354-7128 MacFeather
17 408 496-7223 White
18 408 286-2428 O'Leary
19 219 547-9982 DeFrance
2.如果像几位所说的那样,我写了2条语句:
select identity(int,1,1) id ,m_OMID,m_DocName into #TempTable1 from ISOLDBNOTICE where m_UserID = '2K005' ORDER BY m_DocName ASC
select identity(int,1,1) id ,m_OMID,m_DocName into #TempTable2 from ISOLDBNOTICE where m_UserID = '2K005' ORDER BY m_DocName DESC得到两个临时表,然后我查到m_DocName 为a的两个id都是1,这个应该证明是先排好序,再增加“自增加”id的,不知道结论是否正确?