create proc proc_searchList
@type int,--1.查询全部,2。根据条件默认查询,人气,信誉都按照从高到低查询
@sql nvarchar(200),--传入sql
@startIndex int,
@endIndex int
as
set nocount on
if(1=@type)
begin
declare @indextable1 table(id int identity(1,1),nid int)
set rowcount @endIndex
insert into @indextable1(nid) select user_ID from Kk_Users where type=0 order by ifshenhe desc
select user_ID,user_NoID,nickname,xingming,age,xingzuo,height,weight,sanwei,faxing,fase,xiema,jiankuan,xueli,techang,touxiang,tuijian,xinyu,renqi,ifguanfang,ifshouji,data,type,ifshenhe,hob_ID,style_ID,dbo.getStyleName(style_ID) as style
from Kk_Users k ,@indextable1 t where k.user_ID=t.nid
and t.id between @startIndex and @endIndex order by ifshenhe desc
end
if(2=@type)
begin
declare @str nvarchar(4000)
declare @indextable2 table(id int identity(1,1),nid int)
set rowcount @endIndex
set @str='insert into '+@indextable2(nid)+'select user_ID from Kk_Users '+@sql +'
select user_ID,user_NoID,nickname,xingming,age,xingzuo,height,weight,sanwei,faxing,fase,xiema,jiankuan,xueli,techang,touxiang,tuijian,xinyu,renqi,ifguanfang,ifshouji,data,type,ifshenhe,hob_ID,style_ID,dbo.getStyleName(style_ID) as style
from Kk_Users k ,'+indextable2+' t where k.user_ID=t.nid
and t.id between '+@startIndex+' and '+@endIndex
exec(@str)
print @str
end
set nocount off
go
错误服务器: 消息 137,级别 15,状态 2,过程 proc_searchList,行 23
必须声明变量 '@indextable2'。
错误在标红的那一行上。
sql 存储过程分页