能否使用select或其他SQL语句取出表中具体某一行(具体是哪一行随即指定)的记录?SQL代码应该怎么编写。请指教!谢谢!

解决方案 »

  1.   


    declare @i int
    declare @sql varchar(200)
    set @i='5'set @sql='select top 1 *  from t where 序号 not in(select top '
    set @sql=@sql+cast(@i-1 as varchar)+' 序号 from t)'
    exec(@sql)
      

  2.   

    select * from tablename  a  where n=(select count(*) from tablename where fieldname<=a.fieldname)
      

  3.   

    create table ta(ID int,f1 varchar(50),myvalue int)insert ta select 100,'a',10 
    union all select 200,'b',20
    union all select 300,'c',30
    union all select 400,'d',40 declare @i int
    declare @sql varchar(200)
    set @i='4'set @sql='select top 1 *  from ta where ID not in(select top '
    set @sql=@sql+cast(@i-1 as varchar)+' ID from ta)'
    exec(@sql)drop table ta
      

  4.   

    就用SQL语句老实的查询不就得了
      

  5.   

    create table ta(ID int,f1 varchar(50),myvalue int)
    godeclare @count
    select @count = count(*) from tadeclare @rank int
    set @rank = ceiling(@count*rand())  with temp 
    as
    (
    select *,row_number() over(order by ID) as rank from ta
    )
    select ID,f1,Myvalue from temp
    where rank = @rank
      

  6.   

    select * from tablename
    where ........