--exec SSP_GetCompnayDetails 'A',0,10
--exec SSP_GetCompnayDetails 'A',10,10
CREATE PROC SSP_GetCompnayDetails
(
@CompanyNameStartsWith NVARCHAR(100),
@RecordCount INT =0,
@PazeSize INT =10
)
AS
BEGIN
SET NOCOUNT ON;
;WITH CTE AS
(
SELECT Row_number() OVER(ORDER BY CustomerID) ROW,
CustomerID,
CompanyName,
ContactName,
ContactTitle,
Address,
City,
Region,
PostalCode,
COuntry,
Phone,
Fax
FROM customers c
WHERE c.CompanyName like '%'+ @CompanyNameStartsWith + '%'
)
SELECT ct.*,
(SELECT COUNT(CTE.CustomerID) FROM CTE)TotalRecord
FROM CTE ct WHERE ct.ROW BETWEEN @RecordCount + 1 AND @RecordCount +@PazeSize
END
No comments:
Post a Comment