select newid() --GUID号行不行?

解决方案 »

  1.   

    不好意思,没看清楚题目
    --解决思路:
    --把两个数据范围的值,循环找出来
    --再从数据中newid()随机取出来,然后把取了的数据,踢出去,循环到,所有数据都取完!
      

  2.   

    我想写一个函数 最终结果如下:
    select functionXXX('开始数','结束数','其他参数')
      

  3.   

    create table yourtb
    (
    id bigint
    )insert into yourtb
    select 8880987654321 union all
    select 8880987654322create function f_getnumber(@i bigint,@j bigint)
    returns  bigint
    as
    begin
    while (@i<=@j)
    begin
    if not exists(select 1 from yourtb where id=@i)
                return @i
            else
                set @i=@i+1
    end
    return @j
    end
    goselect dbo.f_getnumber(8880987654321,8880987654388)------------------
    8880987654323(所影响的行数为 1 行)
      

  4.   

    didoleo(冷月无声)  的不错。
    不过要是我多加一个参数 @c 作为查询条件的话,就出不来,不知道为啥 if not exists(select 1 from yourtb where id=@i) 
    修改为
    if not exists(select 1 from yourtb where id=@i and xx=@c)