高人求教,在将nvarchar值转换成数据类型 int 时失败。
ALTER PROCEDURE [dbo].[SP_Page]
(
@PageIndex int,--当前页面
@PageSize int,--页面大小
@SemesterName nvarchar(50),--学期名
@OrgID nvarchar(50),--园所ID
@sortColumn nvarchar(100),--按此列排序
--@tolRecord int output,--总记录数
@ParentID int--在Category表中的父ID
--@tolPage int output --总页数
)
as
if len(@sortColumn) = 0
set @sortColumn = ' a.PKStudentID '
declare @sql1 nvarchar(1000)
declare @sql2 nvarchar(max)
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound = @PageSize*(@PageIndex-1)+1
set @PageUpperBound = @PageSize +@PageLowerBound
--exec sp_executesql @sql1,N'@temp int output',@tolRecord output
----获取页总数
--set @tolPage = ceiling(@tolRecord *1.0/@PageSize)
--查询记录
set @sql2 = '
select * from
(ROW_NUMBER() over(order by ' + @sortColumn+ ' ) as RoeNumber,
a.StudentNo,a.StudentName,a.Gender,a.Birthday,a.EnrolmentDate,b.CategoryName,
a.ParentsName,a.ParentsMobile,a.ParentsAddress,c.Score from student a,category b,student_semester_ships c,org d,classtb e,semester f
where b.ParentID =' +@ParentID +' and a.FKClassID = e.PKClassID and e.FKOrgID= d.PKOrgID and a.FKOrgID = d.PKOrgID and f.SemesterName='+ @SemesterName +'
and a.PKStudentID = c.FKStudentID and f.PKSemesterID = c.FKSemesterID and a.FKNurseryTypeID = b.PKCategoryID and d.PKOrgID='+ @OrgID + ' )rn
where rn.RowNumber between ' + convert(varchar(10),@PageLowerBound) + ' and ' + convert(varchar(10), @PageUpperBound)
EXEC sp_executesql @sql2
exec SP_Page 1,2,'2013年上学期','496cd2b0-336a-4135-84b8-14467903e653','a.PKStudentID','4'
--错误信息
消息 245,级别 16,状态 1,过程 SP_Page,第 28 行
在将 nvarchar 值 '
select * from
(ROW_NUMBER() over(order by a.PKStudentID ) as RoeNumber,
a.StudentNo,a.StudentName,a.Gender,a.Birthday,a.EnrolmentDate,b.CategoryName,
a.ParentsName,a.ParentsMobile,a.ParentsAddress,c.Score from student a,category b,student_semester_ships c,org d,classtb e,semester f
where b.ParentID =' 转换成数据类型 int 时失败。