0

前任:

 @productName varchar(50),
    @pageStart int,
    @pageEnd int,
    @result varchar(MAX)

    set @result = select * from products where productName like '%@productName%' 

    return select from @result where section between @pageStrat to  @pageEnd

这就是我的想象,如果这是正确的?或者有一个语句可以做结果

4

2 回答 2

1
declare @productName varchar(50),
    @pageStart int,
    @pageEnd int,
    @result varchar(MAX)

select  *  from (select *,ROW_NUMBER() over (order by ID) as row from products where 
productName like @productName) a where a.row between @pageStart and @pageEnd
于 2013-08-24T01:42:45.290 回答
1

Replace

'%@productName%' 

with

'%' + @productName + '%'

You are looking for strings that contain the literal "@productName" and I don't think that's what you wanted. Also:

between @pageStrat to  @pageEnd

should be

between @pageStart and @pageEnd

note the misspelled @pageStart and the "to" instead of "and" in your version.

于 2013-08-24T02:40:26.320 回答