reate PROCEDURE Sp_Conn_Sort
(
@tblName varchar(
@strGetFields varchar(
@fldName varchar(
@PageSize int =
@PageIndex int =
@doCount bit =
@OrderType bit =
@strWhere varchar(
)
AS
declare @strSQL varchar(
declare @strTmp varchar(
declare @strOrder varchar(
if @doCount !=
begin
if @strWhere !=
set @strSQL =
else
set @strSQL =
end
else
begin
if @OrderType !=
begin
set @strTmp =
set @strOrder =
end
else
begin
set @strTmp =
set @strOrder =
end
if @PageIndex =
begin
if @strWhere !=
set @strSQL =
else
set @strSQL =
end
else
begin
set @strSQL =
+ @tblName +
if @strWhere !=
set @strSQL =
+ @tblName +
+ @fldName +
+ @fldName +
+ @strOrder +
end
end
exec (@strSQL)
sql server
Create PROC P_viewPage
/**//*
nzperfect [no_mIss] 高效通用分頁存儲過程(雙向檢索)
敬告
ps教程:Sql語句為
*/
@TableName VARCHAR(
@FieldList VARCHAR(
@PrimaryKey VARCHAR(
@Where VARCHAR(
@Order VARCHAR(
@SortType INT
@RecorderCount INT
@PageSize INT
@PageIndex INT
@TotalCount INT OUTPUT
@TotalPageCount INT OUTPUT
AS
SET NOCOUNT ON
IF ISNULL(@TotalCount
SET @Order = RTRIM(LTRIM(@Order))
SET @PrimaryKey = RTRIM(LTRIM(@PrimaryKey))
SET @FieldList = REPLACE(RTRIM(LTRIM(@FieldList))
WHILE CHARINDEX(
BEGIN
SET @Order = REPLACE(@Order
SET @Order = REPLACE(@Order
END
IF ISNULL(@TableName
or ISNULL(@PrimaryKey
or @SortType <
or @RecorderCount <
BEGIN
PRINT(
RETURN
END
IF @SortType =
BEGIN
IF (UPPER(RIGHT(@Order
BEGIN PRINT(
END
DECLARE @new_where
DECLARE @new_where
DECLARE @new_order
DECLARE @new_order
DECLARE @new_order
DECLARE @Sql VARCHAR(
DECLARE @SqlCount NVARCHAR(
IF ISNULL(@where
BEGIN
SET @new_where
SET @new_where
END
ELSE
BEGIN
SET @new_where
SET @new_where
END
IF ISNULL(@order
BEGIN
IF @SortType =
BEGIN
SET @new_order
SET @new_order
END
IF @SortType =
BEGIN
SET @new_order
SET @new_order
END
END
ELSE
BEGIN
SET @new_order
END
IF @SortType =
BEGIN
SET @new_order
SET @new_order
SET @new_order
SET @new_order
SET @new_order
IF @FieldList <>
BEGIN
SET @new_order
SET @FieldList =
WHILE CHARINDEX(
BEGIN
IF CHARINDEX(SUBSTRING(
BEGIN
SET @FieldList =
@FieldList +
END
SET @new_order
SUBSTRING(@new_order
END
SET @FieldList = SUBSTRING(@FieldList
END
END
SET @SqlCount =
+ CAST(@PageSize AS VARCHAR)+
IF @RecorderCount =
BEGIN
EXEC SP_EXECUTESQL @SqlCount
@TotalCount OUTPUT
END
ELSE
BEGIN
Select @TotalCount = @RecorderCount
END
IF @PageIndex > CEILING((@TotalCount+
BEGIN
SET @PageIndex = CEILING((@TotalCount+
END
IF @PageIndex =
BEGIN
IF @PageIndex =
BEGIN
SET @Sql =
+ @TableName + @new_where
END
IF @PageIndex >= CEILING((@TotalCount+
BEGIN
SET @Sql =
+
+
+ @TableName + @new_where
+ @new_order
END
END
ELSE
BEGIN
IF @SortType =
BEGIN
IF @PageIndex <= CEILING((@TotalCount+
BEGIN
SET @Sql =
+ @TableName + @new_where
+
+ STR(@PageSize*(@PageIndex
+
+ @new_where
END
ELSE
BEGIN
SET @Sql =
+
+ @FieldList +
+ @TableName + @new_where
+
+ STR(@TotalCount
+
+ @new_where
+
END
END
IF @SortType =
BEGIN
IF @PageIndex <= CEILING((@TotalCount+
BEGIN
SET @Sql =
+ @TableName + @new_where
+
+ STR(@PageSize*(@PageIndex
+
+ @new_where
END
ELSE
BEGIN
SET @Sql =
+
+ @FieldList +
+ @TableName + @new_where
+
+ STR(@TotalCount
+
+ @new_where
+
END
END
IF @SortType =
BEGIN
IF CHARINDEX(
BEGIN PRINT(
IF @PageIndex <= CEILING((@TotalCount+
BEGIN
SET @Sql =
+
+
+
+ @new_order
END
ELSE
BEGIN
SET @Sql =
+
+
+
+ @new_order
END
END
END
PRINT(@SQL)
EXEC(@Sql)
From:http://tw.wingwit.com/Article/program/MySQL/201311/29564.html