我创建了一个用于搜索的存储过程,但搜索无法正常工作。你能告诉我在这个存储过程中我做错了什么吗?
ALTER PRocedure [dbo].[uspGetAddressByClientAndCode]
@PageIndex INT = 1,
@PageSize INT = 10,
@ClientId int,
@clientName varchar(40)= null,
@Code varchar(2)=null,
@RecordCount INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SELECT * FROM (
SELECT ROW_NUMBER() OVER (ORDER BY AD.[CLIENTID] DESC) AS RowNumber
,AD.[NAME]
,AD.[ADDR]
,AD.[CITY]
,AD.[STPROV]
,AD.[ZIPPOSTAL]
,AD.[COUNTRY]
,AD.[ZONE]
,AD.[CLIENTID]
,CL.BCLIENT
,AD.ADDRESSID
FROM
[Address] Ad
INNER JOIN
client CL ON CL.CLIENTID = AD.[CLIENTID]
WHERE
AD.CLIENTID = @ClientId
AND (AD.NAME IS NULL OR AD.NAME Like @clientName +'%')
AND (AD.code IS NULL OR AD.code = @Code)
) As PageTable
WHERE
RowNumber BETWEEN (@PageIndex -1) * @PageSize + 1 AND (((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
END
答案 0 :(得分:0)
即使不清楚为什么这个存储过程不能正常工作我假设你必须改变WHERE子句,如下所示:
WHERE
AD.CLIENTID = @ClientId
AND (@clientName IS NULL OR AD.NAME Like @clientName +'%')
AND (@Code IS NULL OR AD.code = @Code)