高级自定义查询、分页、多表联合存储过程

baby雪儿983

baby雪儿983

2016-01-29 16:04

高级自定义查询、分页、多表联合存储过程,高级自定义查询、分页、多表联合存储过程
 

分页存储过程代码如下:
ALTER PROCEDURE [dbo].[Task_SelectPagedAndSorted]
(
    @ProjectID uniqueidentifier,
    @ProjectAreaID uniqueidentifier,
    @DepartmentID uniqueidentifier,
    @ChiefID uniqueidentifier,
    @State nvarchar(32),
    @Priority int,
    @Triage nvarchar(32),
    @PlanStartDateF datetime,
    @PlanStartDateL datetime,
    @PlanEndDateF datetime,
    @PlanEndDateL datetime,
    @CompletedDateF datetime,
    @CompletedDateL datetime,
    @SortExpression nvarchar(256),
    @StartRowIndex int,
    @MaximumRows int
)   
AS

DECLARE @sql nvarchar(4000)
DECLARE @ViewSql nvarchar(4000)
DECLARE @WhereClause nvarchar(2000)
DeCLARE @FEndRowIndex int
DeCLARE @FStartRowIndex int
DeCLARE @FMaximumRows int
DeCLARE @FSortExpression nvarchar(256)

-- Make sure a @sortExpression is specified
IF LEN(@SortExpression) 0
  SET @FSortExpression = @SortExpression
ELSE
  SET @FSortExpression = 'ChangedDate DESC'

if (@StartRowIndex is null)
  SET @FStartRowIndex = 0;
else
  SET @FStartRowIndex = @StartRowIndex
if (@MaximumRows is null) or (@MaximumRows <= 0)
  SET @FMaximumRows = 1000;
else
  SET @FMaximumRows = @MaximumRows

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/sqlserver/)

SET @FEndRowIndex = @FStartRowIndex + @FMaximumRows

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/sqlserver/)

SET @WhereClause = 'WHERE --'
if not ((@ProjectID is null) or (@ProjectID = '00000000-0000-0000-0000-000000000000'))
  SET @WhereClause = @WhereClause + 'AND
    ([ProjectID] = ''' + CAST(@ProjectID as nvarchar(64)) + ''')'
if not ((@ProjectAreaID is null) or (@ProjectAreaID = '00000000-0000-0000-0000-000000000000'))
  SET @WhereClause = @WhereClause + 'AND
    ([ProjectAreaID] = ''' + CAST(@ProjectAreaID as nvarchar(64)) + ''')'
if not ((@DepartmentID is null) or (@DepartmentID = '00000000-0000-0000-0000-000000000000'))
  SET @WhereClause = @WhereClause + 'AND
    ([DepartmentID] = ''' + CAST(@DepartmentID as nvarchar(64)) + ''')'
if not ((@ChiefID is null) or (@ChiefID = '00000000-0000-0000-0000-000000000000'))
  SET @WhereClause = @WhereClause + 'AND
    ([ChiefID] = ''' + CAST(@ChiefID as nvarchar(64)) + ''')'
if  LEN(@State) 0
  SET @WhereClause = @WhereClause + 'AND
    ([State] = ''' + @State + ''')'
if not ((@Priority is null) or (@Priority < 0))
  SET @WhereClause = @WhereClause + 'AND
    ([Priority] = ' + CONVERT(nvarchar(10), @Priority) + ')'
if  LEN(@Triage) 0
  SET @WhereClause = @WhereClause + 'AND
    ([Triage] = ''' + @Triage + ''')'
if not (@PlanStartDateF is null)
  SET @WhereClause = @WhereClause + 'AND
    (([PlanStartDate] is null) or ([PlanStartDate] = CAST(''' + CAST(@PlanStartDateF as nvarchar)  + ''' AS datetime)))'
if not (@PlanStartDateL is null)
  SET @WhereClause = @WhereClause + 'AND
    (([PlanStartDate] is null) or ([PlanStartDate] <= CAST(''' + CAST(@PlanStartDateL as nvarchar)  + ''' AS datetime)))'
if not (@PlanEndDateF is null)
  SET @WhereClause = @WhereClause + 'AND
    (([PlanEndDate] is null) or ([PlanEndDate] = CAST(''' + CAST(@PlanEndDateF as nvarchar)  + ''' AS datetime)))'
if not (@PlanEndDateL is null)
  SET @WhereClause = @WhereClause + 'AND
    (([PlanEndDate] is null) or ([PlanEndDate] <= CAST(''' + CAST(@PlanEndDateL as nvarchar)  + ''' A

展开更多 50%)
分享

猜你喜欢

高级自定义查询、分页、多表联合存储过程

SQLServer
高级自定义查询、分页、多表联合存储过程

SQLCLR(二)存储过程和自定义函数

编程语言 网络编程
SQLCLR(二)存储过程和自定义函数

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

jsp 自定义分页标签

Web开发
jsp 自定义分页标签

自定义PHP分页函数

PHP
自定义PHP分页函数

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

GridView控件自定义分页详解

Web开发
GridView控件自定义分页详解

存储过程分页

ASP
存储过程分页

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

Wii年度RPG大作《最后的故事》系统详尽解析

Wii年度RPG大作《最后的故事》系统详尽解析

《战国无双3猛将传》武器搭配心得及推荐

《战国无双3猛将传》武器搭配心得及推荐
下拉加载更多内容 ↓