create table #tblSets (
moduleexamID int,
moduleId int,
nrofitems int
)
go
create table #tblQuestions (
moduleexamID int,
body varchar(1024)
)
go
insert into #tblQuestions values
(20,'aaaaaa'),
(20,'bbbbbb'),
(20,'cccccc'),
(20,'dddddd'),
(21,'eeeeee'),
(21,'ffffff'),
(20,'gggggg')
go
insert into #tblSets values
(20,1,1),
(20,2,2),
(21,1,1),
(22,1,3)
go
select top (
select sum(s.nrofitems)
from #tblSets s
where s.moduleexamID=20
) *, newid() as id
from #tblQuestions q
where q.moduleexamID=20
order by id
go
請不要喊叫 –
的SQL Server的什麼版本? –
MS SQL Server 2005 – eirishainjel