数据库篇之存储过程[bsp_getfavoriteproductlist](非官方版本)

差异如图:

更新语句如下:

DROP PROCEDURE [bsp_getfavoriteproductlist]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [bsp_getfavoriteproductlist]
@pagesize int,
@pagenumber int,
@uid int
AS
BEGIN
	SET NOCOUNT ON;
	
	IF @pagenumber=1
	BEGIN
		SELECT [temp1].[recordid],[temp1].[uid],[temp1].[state],[temp1].[addtime],[temp1].[pid],[temp2].[name],[temp2].[shopprice],[temp2].[showimg] FROM
		(SELECT TOP(@pagesize) [recordid],[uid],[pid],[state],[addtime] FROM [bsp_favorites] WHERE [uid]=@uid ORDER BY [recordid] DESC) AS [temp1]
		LEFT JOIN [bsp_products] AS [temp2]
		ON [temp1].[pid]=[temp2].[pid]
	END
	ELSE
	BEGIN
		SELECT [temp1].[recordid],[temp1].[uid],[temp1].[state],[temp1].[addtime],[temp1].[pid],[temp2].[name],[temp2].[shopprice],[temp2].[showimg] FROM
		(SELECT TOP(@pagesize) [recordid],[uid],[pid],[state],[addtime] FROM [bsp_favorites] WHERE [uid]=@uid AND [pid] NOT IN
		(SELECT TOP(@pagesize*(@pagenumber-1)) [pid] FROM [bsp_favorites] WHERE [uid]=@uid ORDER BY [recordid] DESC) ORDER BY [recordid] DESC) AS [temp1]
		LEFT JOIN [bsp_products] AS [temp2]
		ON [temp1].[pid]=[temp2].[pid]
	END
	
END
GO


©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页