Re: [SQL]如何將查詢出來的結果,多加一欄流水號?

看板Database作者 (矇面加菲獅)時間18年前 (2006/07/16 12:30), 編輯推噓2(200)
留言2則, 2人參與, 最新討論串2/5 (看更多)
※ 引述《artingo (生命需要一些挑戰)》之銘言: : 例如執行一段SQL查詢,結果如下: : Name Score : ------------ : Andy 75 : Bob 60 : Cindy 80 : 但我要讓他在顯示時,自動產生一欄流水號 : 變成: : No. Name Score : -------------------- : 1 Andy 75 : 2 Bob 60 : 3 Cindy 80 : 那麼該如何作呢? 使用 SQL 查詢語法: /* 建立一個有自動編號的暫存資料表 */ create table temp_table ( [No] int identity(1,1) not null, [Name] varchar(16) not null, [Score] int null constraint DF_temp_table default(0), primary key clustered ( [Score] ) on [primary] ) on [primary] GO /* 將資料複製到暫存資料表 */ insert into temp_table select * from [你的資料表名稱] /* 取出含有流水號的資料 */ select * from temp_table 不使用 SQL 語法(寫程式:ASP.NET) Do While SqlDataReader1.Read() Response.Write "<tr>" Response.Write "<td>" & i & "</td>" Resposne.Write "<td>" & SqlDataReader1("Name") & "</td>" Response.Write "<td>" & SqlDataReader1("Score") & "</td>" Response.Write "</tr>" i += 1 Loop -- ▃▅▇▆▄ ▆▂▃ ` 逝去感如何能留住,半點遺留殊不易,██▅▇▄▃ ▇▃▂" . █████████▃i ▁▄▇ 更多悽悽慘慘的遭遇………██▆▃ █▅▆▃ˍ▄* ▂█▄▇▅▂. 我不知道,王~八~蛋~~! ▂▆███ █▄▃ 。fumizuki。Check。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.184.116.195

07/16 14:26, , 1F
我覺得用前端語言來處理比較好...
07/16 14:26, 1F

07/16 14:50, , 2F
是前端比較好
07/16 14:50, 2F
文章代碼(AID): #14kS3lL4 (Database)
討論串 (同標題文章)
文章代碼(AID): #14kS3lL4 (Database)