ALTER PROC [dbo].[Usp_SelectQuestion]
@NoOfQuestion int
AS
BEGIN
Declare @CNT int
Declare @test int
Declare @x int
Declare @y int
set @x = 1;
set @y = 1;
set @CNT=(Select Count(*) from (select Distinct(setno)from onlin) AS A)
set @test=@NoOfQuestion/@CNT
while (@x <= @CNT)
begin
select top (@test) * from onlin where setno = @x order by NEWID()
set @x = @x + 1
end
END
このストアドプロシージャでは、ループごとに単一のテーブルとして出力を取得しているため、出力として複数のテーブルを取得していますが、単一のテーブルにすべての行が必要です。ユニオンを通じて達成できると思いますが、使用方法がわかりません。