hi i tried one of your sample here is the code below
ALTER PROCEDURE [dbo].[paging](
@PageNo int = 1,
@ItemsPerPage int = 20,
@TotalRows int out,
@fname varchar(50) = NULL,
@mname varchar(50) = NULL,
@lname varchar(50) = NULL,
@qfr varchar(10) = NULL
)
AS
BEGIN
SET NOCOUNT ON
DECLARE
@StartIdx int,
@SQL nvarchar(max),
@SQL_Conditions nvarchar(max),
@EndIdx int
IF @PageNo < 1 SET @PageNo = 1
IF @ItemsPerPage < 1 SET @ItemsPerPage = 10
SET @StartIdx = (@PageNo -1) * @ItemsPerPage + 1
SET @EndIdx = (@StartIdx + @ItemsPerPage) - 1
SET @SQL = N'SELECT path_front , pid
FROM (
SELECT ROW_NUMBER() OVER(ORDER BY fname) AS Row, path_front, pid
FROM searcherview
where (fname = @firstname or @firstname = '') and (mname = @midname or @midname = '') and (lname = @lastname or @lastname = '') and (qualifier = @quali or @quali = '')
) AS tbl WHERE Row >= '
+ CONVERT(varchar(9), @StartIdx) + ' AND
Row <= ' + CONVERT(varchar(9), @EndIdx)
EXEC sp_executesql @SQL,
@params = N'@firstname varchar(50), @midname varchar(50), @lastname varchar(50), @quali varchar(10)',
@firstname = @fname, @midname = @mname, @lastname=@lname, @quali = @qfr
SET @SQL = 'SELECT @TotalRows=COUNT(*) FROM searcherview WHERE (fname = @firstname)'
EXEC sp_executesql
@query = @SQL,
@params = N'@TotalRows INT OUTPUT ,@firstname varchar(50)',@firstname = @fname,
@TotalRows = @TotalRows OUTPUT
END
now when it executes the last sp_executesql returns as expected but the first returs null
is there something wrong with the code specifically in the OR statement?
thanks