Здравствуйте, ilya_ny, Вы писали:
_>если уверен, что пробелов в таблице среди id нет, то можно сразу вернуть @id_min + (@id_max — @id_min) * @rnd
_>--
_>с другой стороны я не уверен, что понял вопрос
В конечном счете я написал так:
CREATE FUNCTION [dbo].[funcLaunch](@rnd_val float)
RETURNS int
AS
-- Returns the stock level for the product.
BEGIN
declare @cur cursor
set @cur = cursor for select kod from qlaunch
open @cur
declare @cur_val int
declare @prev_val int
fetch next from @cur into @cur_val
set @prev_val = @cur_val
declare @cond int
set @cond = 0
declare @total_records int
select @total_records = count(kod) from qlaunch
declare @rand_num int
set @rand_num = round((@total_records + 1) * @rnd_val, 0)
while @cond < @rand_num
begin
set @cond = @cond + 1
set @prev_val = @cur_val
fetch next from @cur into @cur_val
end
return @prev_val
END;
Всем большое спасибо!