hi
refer below thread
http://www.aspforums.net/Threads/176918/how-to-remove-duplicate-record-while-paging-in-SQL-Server/
I wrote below SP:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[NewOrder_Information]
@PageIndex INT = 1
,@PageSize INT = 20
,@RecordCount INT OUTPUT
AS
BEGIN
SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 0) ASC)AS RowNumber,PeygiriCode,PostType,NAME,id,Quantity,Tell,date,address,PostT,[time],TotalOrder,mobile
INTO #Results
FROM (SELECT ROW_NUMBER() OVER(PARTITION BY PeygiriCode ORDER BY id ASC) RNo,PeygiriCode,PostType,NAME,id,Quantity,Tell,date,(State+'-'+City+'-'+'منطقه:'+Zone) as address,PostT,[Time],TotalOrder,Mobile FROM Order_Users)a
WHERE RNo = 1
SELECT @RecordCount = COUNT(*) FROM #Results
SELECT PeygiriCode,PostType,NAME,id,Quantity,Tell,date,address,PostT,Time,TotalOrder,Mobile FROM #Results
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
END
Now I have SP that search in 3 table with condition below is SP:
USE [Digimaster]
GO
/****** Object: StoredProcedure [dbo].[GetCustomersPageWiseSearchAD] Script Date: 11/10/2016 21:19:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
alter procedure [dbo].[GetCustomersPageWiseSearchAD1]
@PageIndex INT = 1
,@PageSize INT = 12
,@RecordCount INT OUTPUT
,@search nvarchar(100)
AS
BEGIN
SET NOCOUNT ON;
SELECT ROW_NUMBER() OVER
(
ORDER BY [Date] desc
)AS RowNumber
,[ID]
,[PeygiriCode]
,[Rahgiricode]
,[Quantity]
,[Name]
,[Tell]
,(State+'-'+City+'-'+'منطقه:'+Zone) as address
,PostT
,sefaresh
,color
INTO #Results
FROM [Order_Send]
WHERE (PeygiriCode LIKE '%' + @search + '%' OR @search = '')
UNION ALL
SELECT ROW_NUMBER() OVER
(
ORDER BY [Date] desc
)AS RowNumber
,[ID]
,[PeygiriCode]
,'' as [Rahgiricode]
,[Quantity]
,[Name]
,[Tell]
,(State+'-'+City+'-'+'منطقه:'+Zone) as address
,PostT
,sefaresh
,color
FROM [Order_Users]
WHERE (PeygiriCode LIKE '%' + @search + '%' OR @search = '')
UNION ALL
SELECT ROW_NUMBER() OVER
(
ORDER BY [Date] desc
)AS RowNumber
,[ID]
,[PeygiriCode]
,'' as [Rahgiricode]
,[Quantity]
,[Name]
,[Tell]
,(State+'-'+City+'-'+'منطقه:'+Zone) as address
,PostT
,sefaresh
,color
FROM Order_Confirm
WHERE (PeygiriCode LIKE '%' + @search + '%' OR @search = '')
SELECT @RecordCount = COUNT(*) FROM #Results
SELECT * FROM #Results
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
DROP TABLE #Results
END
now I want do same thing for above SP how I can do it?
Best regards
neda