Access教程
  • sql server教程
  • MySQL教程 DB2教程 ORACLE教程
    当前位置:教程 > 数据库 > sql server教程 > 正文

    分页 SQLServer存储过程(2)

    编辑:教程网 来源:网络 时间:2011年09月07日 15:46

    select name from sysobjects where xtype='PK' and [email protected]_ID
    )))
    select @strfd=substring(@strfd,2,2000)
    ,@strjoin=substring(@strjoin,5,4000)
    ,@strwhere=substring(@strwhere,5,4000)
    goto lbusepk
    end
    end
    end
    else
    goto lbusetemp

    /*--使用标识列或主键为单一字段的处理方法--*/
    lbuseidentity:
    exec('select top '[email protected][email protected]+' from '[email protected]
    +' where '[email protected]+' not in(select top '
    [email protected]+' '[email protected]+' from '[email protected][email protected]
    +')'[email protected]
    )
    return

    /*--表中有复合主键的处理方法--*/
    lbusepk:
    exec('select '[email protected]+' from(select top '[email protected]+' a.* from
    (select top 100 percent * from '[email protected][email protected]+') a
    left join (select top '[email protected]+' '[email protected]+'
    from '[email protected][email protected]+') b on '[email protected]+'
    where '[email protected]+') a'
    )
    return

    /*--用临时表处理的方法--*/
    lbusetemp:
    select @FdName='[ID_'+cast(newid() as varchar(40))+']'
    ,@Id1=cast(@PageSize*(@PageCurrent-1) as varchar(20))
    ,@Id2=cast(@PageSize*@PageCurrent-1 as varchar(20))

    exec('select '[email protected]+'=identity(int,0,1),'[email protected]+'
    into #tb from'[email protected][email protected]+'
    select '[email protected]+' from #tb where '[email protected]+' between '
    [email protected]+' and '[email protected]
    )

    GO

    ?


  • 原文来自 教程网 转载请注明:http://www.websmill.com/shujuku/sql_server/22048.html

  • 上一篇:Sql Server基本函数
  • 下一篇:品味SQL Server 2005的几个新功能