您的位置:首页 > 数据库

SQL分页存储过程实例

2016-06-12 10:03 435 查看
-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE proc_page_split1
-- Add the parameters for the stored procedure here
@pageindex int,
@pagesize int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT top (@pagesize)   basic_staff.staffid, basic_staff.name,(case  basic_staff.sex when 0 then '女' when 1 then '男' end) AS sex, basic_department.name AS departmentname,
basic_role.name AS rolename
FROM      basic_staff LEFT JOIN
basic_department ON basic_staff.depid = basic_department.depid LEFT JOIN
basic_role ON basic_staff.roleid = basic_role.roleid
where basic_staff.ID not in (select top (@pagesize*@pageindex) ID from basic_staff)  order by basic_staff.ID
END
GO
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: