日期:2014-05-17 浏览次数:20482 次
IF(ISNULL(@par1,'')<>'')
SET @S1=@S1+' AND col1 LIKE '''+@par1+'%'''
IF(ISNULL(@par2,0)<>0) --当然:定义的参数如果是整型的话,就用 0
SET @S1=@S1+' AND col2 ='''+@par2+''''
create procedure dbo.ab_Student_GetStudents
(
@pageIndex int,
@pageSize int,
@college nvarchar(30)
)
begin
declare @sqlString nvarchar(500)
declare @start int
declare @finish int
set @start=@pageIndex*@pageSize+1
set @finish=(@pageIndex+1)*@pageSize
set @sqlString='select * from
(
select ab_Students.s_id,
ab_Students.s_name,
ab_Students.s_college,
ab_Students.s_grade,
ab_Students.s_field,
ab_Students.s_telphone,
ab_Students.s_mobile,
ab_Students.s_fax,
ROW_NUMBER() OVER (ORDER BY ab_Students.s_grade DESC,ab_Students.s_id) AS RowNum
from ab_Students where 1=1'
if(ISNULL(@college,'')<>'')
set @sqlString=@sqlString+' s_college= '''+@college+''''
set @sqlString=@sqlString+' )Students
where Students.RowNum between @start and @finish'
exec sp_executesql
@sqlString,
N'@start int, @finish int',
@start,
@finish
end
GO
execute ab_Student_GetStudents 0,6,''能成功但是
execute ab_Student_GetStudents 0,6,'计算机'时提示's_college' 附近有语法错误。
select *
from(
select ab_Students.s_id, ab_Students.s_name, ab_Students.s_college,
ab_Students.s_grade, ab_Students.s_field, ab_Students.s_telphone,
ab_Students.s_mobile, ab_Students.s_fax,
ROW_NUMBER() OVER (ORDER BY ab_Students.s_grade DESC,ab_Students.s_id) AS RowNum
from ab_Students where 1=1 s_college= '计算机' --此处没有连接关键字 and或者or
)Studentswhere Students.RowNum between @start and @finish