怎样建立临时表消除重复行

来源:百度知道 编辑:UC知道 时间:2024/09/23 02:24:57
....
IF @stype='判断类型题库'
while @i <=@snum
begin
select top 1 @sid=序号 from 判断题库 where 难度系数=@sdif order by NEWID()
insert into 试卷套号(套号,题库类型,试题号)values(@TaoHao,@stype,@sid)
set @i=@i+1
end
.........
从判断题库中选出的序号作为试题号存入试卷套号中,会有重复行存在,怎样利用临时表消除重复行?

select top 1 @sid=序号 from 判断题库 where 难度系数=@sdif order by NEWID()
if not exists (select * from 试卷套号 where 套号 = @TaoHao and 试题号 = @sid )
insert into 试卷套号(套号,题库类型,试题号)values(@TaoHao,@stype,@sid)