我在做分页存储,
请问我这个存储过程的判断哪有问题,主要是中间if语句,从页面传入空值时,搜索为空,去掉if语句就没问题
ALTER PROCEDURE dbo.GetAllbooking
(
@PageNumber int,
@ScorePerPage int,--每页显示的信息条数
@PageCount int output, --查询到的总页数
@SelectCount int output,--查询倒的数据总数
@bookid varchar(20),
@userid varchar(20)
)
AS
begin
    create table #temp
    (
    rowid int,
    bookid varchar(20)
    )
    
    SET NOCOUNT ON 
     
     declare @SelectCommand varchar(1000)
     
     
     set @SelectCommand='insert into #temp
     select row_number() over (order by booking.bkdate desc) as row,
     booking.bookid from booking where (booking.bookid is not null)'
     
     if (@bookid is not null)
   
     set @SelectCommand=@SelectCommand+' and (booking.bookid='''+@bookid+''')'
     
     if(@userid is not null)
     begin
     set @SelectCommand=@SelectCommand+' and (booking.userid='''+@userid+''')'
     end
     
     exec(@SelectCommand)
    select   @SelectCount=count(rowid) from #temp
   
     set @pageCount=@SelectCount/@ScorePerPage
     if (@PageCount<(@SelectCount*1.0/@ScorePerPage)) set @PageCount=@PageCount+1
     
     select #temp.rowid,
     booking.bookid, booking.userid, booking.bkdate, booking.productid, booking.toll,
           booking.state,booking.class,booking.area
     from booking inner join #temp on booking.bookid=#temp.bookid
      where  #temp.rowid>(@PageNumber-1)*@ScorePerPage and
       #temp.rowid<=@PageNumber*@ScorePerPage
     
     drop table #temp
     
     end