sql中存储过程出现的有关问题,请高手帮帮忙吧

sql中存储过程出现的问题,请高手帮帮忙吧
这个一段从网上找来的存储过程实现分页功能,我想增加几个参数来传递,却总是出现问题
USE [db_PersonalData]
GO
/****** Object:  StoredProcedure [dbo].[sp_Page_GetOrder]    Script Date: 2015/5/6 15:55:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc  [dbo].[sp_Page_GetOrder]
@startIndex int,
@endIndex int,
@strSql varchar(200),
@strId varchar(20),
@strTableName varchar(30)
as
if @strSql=''
with table_temp as (select row_number() over(order by @strId) as rowIndex,* from Orders)
select * from table_temp where rowIndex between @startIndex and @endIndex

else

with table_temp as (select row_number() over(order by @strId) as rowIndex,* from Orders)
select * from table_temp where rowIndex between @startIndex and @endIndex
我想在select * from table_temp where rowIndex between @startIndex and @endIndex
这个里面 加入一个条件参数and @strSql却出现了“在应使用条件的上下文(在 'AND' 附近)中指定了非布尔类型的”
问题
各个大侠请帮帮忙应该怎样写???
------解决思路----------------------
试试

if @strSql=''
with table_temp as (select row_number() over(order by @strId) as rowIndex,* from Orders)
select * from table_temp where rowIndex between @startIndex and @endIndex

else
begin
  set @strSql='
  with table_temp as (select row_number() over(order by '''
  + @strId + 
  ''') as rowIndex,* from Orders)
  select * from table_temp where rowIndex between '
  + LTRIM(@startIndex) + 
  ' and '
  + LTRIM(@endIndex) +
  ' and ' + @strSql
  exec(@strSql)
end