태그

2014년 12월 7일 일요일

sql non overlapping random number


sql non overlapping random number
중복되지 않는 랜덤 값으로 채우기

ex) Fill random number from 0 to 15

declare @t int = 0
declare @tt table (n int)
while( (select count(n) from @tt) < 15)
begin
 set @t = floor(rand()*15) --Generate 0~15
 if @t not in (select n from @tt)
 begin
  insert into @tt values(@t)
 end
end

select n
from @tt

댓글 없음:

댓글 쓰기