服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: '1' 附近有语法错误。SELECT  top 30*(1-1) p_id FROM paper_control WHERE p_isuse=1 AND ks_isexercise=1 ORDER BY p_addtime DESC

解决方案 »

  1.   

    /*
    在TOP后面使用变量
    (爱新觉罗.毓华(十八年风雨,守得冰山雪莲花开)  2008-01-02  广东深圳)
    */--SQL SERVER 2005 的写法
    use adventureworks
    goDECLARE @Percentage int
    SET @Percentage = 1
    SELECT TOP (@Percentage) PERCENT
    Name
    FROM Production.Product
    ORDER BY Name/*
    Name
    ----------------------
    Adjustable Race
    All-Purpose Bike Stand
    AWC Logo Cap
    BB Ball Bearing
    Bearing Ball
    Bike Wash - Dissolver(6 行受影响)
    */-----------------------------------
    --SQL SERVER 2000 的写法
    create table a([id] [int])
    insert into a(id) values(1)
    insert into a(id) values(2)
    insert into a(id) values(3)
    insert into a(id) values(4)
    insert into a(id) values(5)declare @num as int
    declare @sql as varchar(2000)
    set @num = 2
    set @sql = 'select top ' + cast(@num as char) + ' * from a'
    exec(@sql)drop table a
    /*
    id          
    ----------- 
    1
    2
    */
      

  2.   


    top 30*(1-1)
    出错了TOP后面是能有计算的……
      

  3.   

    谁说不能计算的,括号括起来就可以了SELECT  top(30*(1-1))  p_id FROM paper_control WHERE p_isuse=1 AND ks_isexercise=1 ORDER BY p_addtime DESC
      

  4.   

    囧 红色不能显示啊
    SELECT  top(30*(1-1))  p_id FROM paper_control WHERE p_isuse=1 AND ks_isexercise=1 ORDER BY p_addtime DESC
      

  5.   


     top 30*(1-1)?
     没见过