호랑이 곰방대 시절 AdRotator 에 넣고 돌렸던 기억이;;;
1. 안된다고 한다!
2. 가짜로 확율 랜덤을 만들어 본다.
declare @idx int, @fruit nvarchar(20), @qty int
declare @tmp table (
idx int,
fruit nvarchar(20),
qty int
)
declare @result table (
idx int,
fruit nvarchar(20)
)
insert into @tmp values
(1, '사과', 7),
(2, '딸기', 2),
(3, '포도', 1),
(4, '단감', 3)
select * from @tmp
declare cursor_fruit cursor for
select idx, fruit, qty from @tmp
open cursor_fruit
fetch next from cursor_fruit into @idx, @fruit, @qty
while @@FETCH_STATUS = 0
begin
while @qty > 0
begin
insert into @result values (@idx, @fruit)
set @qty = @qty - 1
end
fetch next from cursor_fruit into @idx, @fruit, @qty
end
close cursor_fruit
deallocate cursor_fruit
select top 1 * from @result order by newid()
3. 다시 1번으로 간다.