SQL可以通过语句
select top n * from tab where somefield=somevalue 
检索到前n行的数据但是现在是,想检索整个表,但是最后一行不要,怎么办?

解决方案 »

  1.   

    declare @n int
    select @n=isnull(count(*)-1, 0) from tab where somefield=somevalue
    exec('select top '+@n+' * from tab where somefield=somevalue ')
      

  2.   

    TO:marco08(天道酬勤) 
    出现了“1行被上次查询影响”结果集什么都没有
      

  3.   

    select * from tab where somefield=somevalue --有多少行數據
      

  4.   

    select * from tab where somefield=somevalue --如果只有一行, 按你的要求最后一行不要, 那麽就不會返回結果集
      

  5.   

    企业管理器里面测试加WHERE條件了嗎?
      

  6.   

    declare @i int
    select @i=count(1) from table where condition=con
    if @i>0 then
    select top @i * from table where condition=con
      

  7.   

    --trydeclare @n int
    select @n=count(*) from tab where somefield=somevalue
    if @n>1
    set @n=@n-1set rowcount @n
    select * from tab where somefield=somevalue
    set rowcount 0
      

  8.   

    TO:hrb2008() 加THEN:
    在关键字“THEN”附近语法错误不加THEN:
    在第一行@i处语法错误
      

  9.   

    TO:marco08(天道酬勤) 和上次的一样,一行被影响,什么都么有
      

  10.   

    最后一个是最新的吗?select * from tab where id <> (select top 1 t1.id from tab t1 order by t1.datetime desc)
      

  11.   

    declare @n int
    select @n=count(*) from tab where somefield=somevalue
    if @n>1
    set @n=@n-1set rowcount @n
    select * from tab where somefield=somevalue
    set rowcount 0---这个应该没问题的,楼主在哪儿看到一行被影响?
      

  12.   

    set nocount on
    declare @n int
    select @n=count(*) from tab where somefield=somevalue
    if @n>1
    set @n=@n-1set rowcount @n
    select * from tab where somefield=somevalue
    set rowcount 0
    SET NOCOUNT OFF
      

  13.   

    wangdehao(找找找(现在很幸福)) 正解。不过感谢所有的人,尤其是marco08(天道酬勤) 一直在关注。马上结贴。