SELECT
(SELECT COUNT(s.computer_name) + 1
FROM pc_hd s
WHERE
s.computer_name <= t.computer_name) AS RunNumber,
t.computer_name,
t.user,
dt.section_name
FROM pc_hd t, section_dt dt
WHERE
t.section_id = dt.section_id
AND
dt.section_name = sec_name
ORDER BY
t.computer_name
SELECT
t.computer_name,
t.[user],
dt.section_name
INTO #x
FROM PC_HD t, sction_dt dt
WHERE
dt.section_name = 'hr'
AND
t.computer_name LIKE 'hr%'
ORDER BY
t.computer_name
GO
SELECT
(SELECT COUNT(computer_name)
FROM #x AS x
WHERE x.computer_name <= y.computer_name) AS Sequence,
computer_name,
[user],
section_name
FROM #x AS y
GO
drop table #x
GO
โดยใช้ query นี้แล้ว
SELECT DISTINCT (select count(s.computer_name) from pc_hd s where " +
"s.computer_name <= t.computer_name), t.computer_name, t.user, " +
"dt.section_name FROM Section_DT dt INNER JOIN (PC_HD t INNER JOIN " +
"Repair_DT rt ON t.computer_name = rt.computer_name) ON " +
"dt.section_id = t.section_id Where t.computer_name in " +
"(SELECT rtt.computer_name FROM Repair_DT rtt Where rtt.Doc_no" +
" like '" + doc_num + "%') Order By t.computer_name";
SELECT DISTINCT
t.computer_name, t.[user], dt.section_name
INTO #x
FROM
section_dt dt
INNER JOIN
(PC_HD t
INNER JOIN
repair_dt rt
ON
t.computer_name = rt.computer_name)
ON
dt.section_id = t.section_id
WHERE
t.computer_name
IN
(SELECT rtt.computer_name FROM repair_dt rtt WHERE rtt.doc_no LIKE '12%') ORDER BY t.computer_name
GO
SELECT
(SELECT COUNT(computer_name)
FROM #x AS x
WHERE x.computer_name <= y.computer_name) AS Sequence,
computer_name,
[user],
section_name
FROM #x AS y
GO
DROP TABLE #x
GO