CodeGen/Templates/DefaultSql/GetPageOfRecentPosts.sql

(完整代码) 1004B



CREATE PROCEDURE [dbo].[<%= model.TableName %>_GetRecent]
(
	@PageIndex int,
	@PageSize int,
	@TotalRows int output
)
AS

BEGIN
	SET NOCOUNT ON;
	SET ANSI_NULLS ON
	SET QUOTED_IDENTIFIER ON

	-- Create a temp table TO store the select results
    CREATE TABLE #posts
    (
        row int IDENTITY (0, 1) NOT NULL,
        id int
    )

	-- If owner, get back all the posts, regardless if they expired or not.
	INSERT INTO #posts (id)
			SELECT Id 
			FROM   <%= model.TableName %> with ( nolock )
			ORDER BY CreateDate desc

	-- Now obtain the <%= model.TableName %> in the page requested
	SELECT    <%= model.TableName %>.*
	FROM      <%= model.TableName %>
	WHERE	  <%= model.TableName %>.Id IN
			(
				SELECT	id 
				FROM  #posts
				WHERE row between ((@PageIndex - 1) * @PageSize) and ( @PageIndex * @PageSize ) -1
			)
	ORDER BY CreateDate desc

	-- Get the total number of records that matched the search.
	select @TotalRows = count(*) from #posts
END

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。