作者fumizuki (蒙面加菲狮)
看板Database
标题Re: [SQL]如何将查询出来的结果,多加一栏流水号?
时间Sun Jul 16 12:59:20 2006
※ 引述《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
1F:推 PsMonkey:我觉得用前端语言来处理比较好... 07/16 14:26
2F:推 fumizuki:是前端比较好 07/16 14:50