i have a problem. the error a search by column name nombreUnit
event 1 very good: find all record whithout search (66 records 5 pagecount=5 pagesize = 15 )
event 2: error : find all record contain in field nombreunit lether M (27 records, pagecont=2 pagesize=1)
the procedure sqlserver show the rows in two pages and 7 rows by screen
this error:to display two pages, one with 15 and one with 12 records
the error happens when
the stored procedure, then display two pages with 6 records each
to display two pages, one with 15 and one with 12 records
CREATE PROCEDURE [dbo].[SearchUnidades]
(
@Codigo varchar(6),
@Nombre varchar(50),
@PageIndex int,
@PageSize int,
@swQuery bit,
@RowsTotal int output
)
AS
BEGIN
DECLARE @query NVARCHAR(1000) =''
DECLARE @PageFirst int
DECLARE @PageLast int
SET @PageFirst =
(@PageIndex * @PageSize) + 1 ; SET @PageLast = (@PageIndex * @PageSize) + @PageSize
SET @query = ' SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY codigo_undmedida) AS RowNumber,
codigo_undmedida, descripcion_undmedida FROM unidadmedida ) AS TBL' +
' WHERE RowNumber BETWEEN ' + CONVERT(varchar(10),@PageFirst) + ' AND ' +
CONVERT(varchar(10),@PageLast)
IF (@Codigo != '' and @swQuery = 1 ) SET @query = @query + ' AND codigo_undmedida LIKE ''' + @Codigo + '%'''
IF (@Nombre != '' and @swQuery = 1) SET @query = @query + ' AND descripcion_undmedida LIKE ''%' + @Nombre + '%'''
EXEC (@query)
SELECT @RowsTotal = COUNT(codigo_undmedida) FROM unidadmedida WHERE descripcion_undmedida LIKE '%' + @Nombre + '%'
RETURN
END