在sql2005数据库执行存储过程出现:关键字 'SET' 附近有语法错误。 怎么处理呀代码如下
就这个存储过程出错,代码如下,求解:GO/******Object:StoredProcedure[dbo].[GetDataSet]ScriptDate:09/21/2...
就这个存储过程出错,代码如下,求解:
GO
/****** Object: StoredProcedure [dbo].[GetDataSet] Script Date: 09/21/2012 09:57:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[GetDataSet]
@TableList Varchar(1024)='*',--搜索表的字段,比如:’id,datatime,job‘,用逗号隔开
@TableName Varchar(100), --搜索的表名
@SelectWhere Varchar(1024)='',--搜索条件,这里不用写where,比如:job=’teacher‘and class='2'
@SelectOrderId Varchar(50),--表主键字段名。比如:id
@SelectOrder Varchar(200)='', --排序,可以使用多字段排序但主键字段必需在最前面.也可以不写,比如:order by class asc
@intPageNo int=1, --页号
@intPageSize int=10 ,--每页显示数
@RecordCount int OUTPUT --总记录数(存储过程输出参数)
as
declare @TmpSelect NVarchar(4000)
declare @Tmp NVarchar(4000)
declare @pagecount int
set nocount on--关闭计数
set @RecordCount=0
set @TmpSelect = 'select @RecordCount=count(*) from '+@TableName+' where '+@SelectWhere
execute sp_executesql
@TmpSelect, --执行上面的sql语句
N'@RecordCount int OUTPUT' , --执行输出数据的sql语句,output出总记录数
@RecordCount OUTPUT
set
if (@RecordCount = 0) --如果没有贴子,则返回零
return 0
set @pagecount=@RecordCount/@intPageSize
if(@RecordCount%@intPageSize>0)
set @pagecount=@pagecount+1
if(@pagecount<=0)
set @pagecount=1
if(@intPageNo>@pagecount)
set @intPageNo=@pagecount
/*判断页数是否正确*/
--if (@intPageNo - 1) * @intPageSize > @RecordCount --页号大于总页数,返回错误
--set @intPageNo=@pagecount
set nocount off--打开计数
if @SelectWhere != ''
begin
set @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' where '+@SelectOrderId+' not in(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+' where '+@SelectWhere +' '+@SelectOrder+') and '+@SelectWhere +' '+@SelectOrder
end
else
begin
set @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' where '+@SelectOrderId+' not in(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+' '+@SelectOrder+') '+@SelectOrder
end
execute sp_executesql @TmpSelect
return(@@rowcount)
GO 展开
GO
/****** Object: StoredProcedure [dbo].[GetDataSet] Script Date: 09/21/2012 09:57:26 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[GetDataSet]
@TableList Varchar(1024)='*',--搜索表的字段,比如:’id,datatime,job‘,用逗号隔开
@TableName Varchar(100), --搜索的表名
@SelectWhere Varchar(1024)='',--搜索条件,这里不用写where,比如:job=’teacher‘and class='2'
@SelectOrderId Varchar(50),--表主键字段名。比如:id
@SelectOrder Varchar(200)='', --排序,可以使用多字段排序但主键字段必需在最前面.也可以不写,比如:order by class asc
@intPageNo int=1, --页号
@intPageSize int=10 ,--每页显示数
@RecordCount int OUTPUT --总记录数(存储过程输出参数)
as
declare @TmpSelect NVarchar(4000)
declare @Tmp NVarchar(4000)
declare @pagecount int
set nocount on--关闭计数
set @RecordCount=0
set @TmpSelect = 'select @RecordCount=count(*) from '+@TableName+' where '+@SelectWhere
execute sp_executesql
@TmpSelect, --执行上面的sql语句
N'@RecordCount int OUTPUT' , --执行输出数据的sql语句,output出总记录数
@RecordCount OUTPUT
set
if (@RecordCount = 0) --如果没有贴子,则返回零
return 0
set @pagecount=@RecordCount/@intPageSize
if(@RecordCount%@intPageSize>0)
set @pagecount=@pagecount+1
if(@pagecount<=0)
set @pagecount=1
if(@intPageNo>@pagecount)
set @intPageNo=@pagecount
/*判断页数是否正确*/
--if (@intPageNo - 1) * @intPageSize > @RecordCount --页号大于总页数,返回错误
--set @intPageNo=@pagecount
set nocount off--打开计数
if @SelectWhere != ''
begin
set @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' where '+@SelectOrderId+' not in(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+' where '+@SelectWhere +' '+@SelectOrder+') and '+@SelectWhere +' '+@SelectOrder
end
else
begin
set @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' where '+@SelectOrderId+' not in(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+' '+@SelectOrder+') '+@SelectOrder
end
execute sp_executesql @TmpSelect
return(@@rowcount)
GO 展开
1个回答
展开全部
换成
CREATE proc [dbo].[GetDataSet]
@TableList Varchar(1024)='*',--搜索表的字段,比如:’id,datatime,job‘,用逗号隔开
@TableName Varchar(100), --搜索的表名
@SelectWhere Varchar(1024)='',--搜索条件,这里不用写where,比如:job=’teacher‘and class='2'
@SelectOrderId Varchar(50),--表主键字段名。比如:id
@SelectOrder Varchar(200)='', --排序,可以使用多字段排序但主键字段必需在最前面.也可以不写,比如:order by class asc
@intPageNo int=1, --页号
@intPageSize int=10 ,--每页显示数
@RecordCount int OUTPUT --总记录数(存储过程输出参数)
as
declare @TmpSelect NVarchar(4000)
declare @Tmp NVarchar(4000)
declare @pagecount int
set nocount on--关闭计数
set @RecordCount=0
set @TmpSelect = 'select @RecordCount=count(*) from '+@TableName+' where '+@SelectWhere
execute sp_executesql
@TmpSelect, --执行上面的sql语句
N'@RecordCount int OUTPUT' , --执行输出数据的sql语句,output出总记录数
@RecordCount OUTPUT
if (@RecordCount = 0) --如果没有贴子,则返回零
return 0
set @pagecount = @RecordCount/@intPageSize
if(@RecordCount%@intPageSize>0)
set @pagecount=@pagecount+1
if(@pagecount<=0)
set @pagecount=1
if(@intPageNo>@pagecount)
set @intPageNo=@pagecount
/*判断页数是否正确*/
--if (@intPageNo - 1) * @intPageSize > @RecordCount --页号大于总页数,返回错误
--set @intPageNo=@pagecount
set nocount off--打开计数
if @SelectWhere != ''
begin
set @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' where '+@SelectOrderId+' not in(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+' where '+@SelectWhere +' '+@SelectOrder+') and '+@SelectWhere +' '+@SelectOrder
end
else
begin
set @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' where '+@SelectOrderId+' not in(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+''+@SelectOrder+') '+@SelectOrder
end
execute sp_executesql @TmpSelect
return(@@rowcount)
GO
CREATE proc [dbo].[GetDataSet]
@TableList Varchar(1024)='*',--搜索表的字段,比如:’id,datatime,job‘,用逗号隔开
@TableName Varchar(100), --搜索的表名
@SelectWhere Varchar(1024)='',--搜索条件,这里不用写where,比如:job=’teacher‘and class='2'
@SelectOrderId Varchar(50),--表主键字段名。比如:id
@SelectOrder Varchar(200)='', --排序,可以使用多字段排序但主键字段必需在最前面.也可以不写,比如:order by class asc
@intPageNo int=1, --页号
@intPageSize int=10 ,--每页显示数
@RecordCount int OUTPUT --总记录数(存储过程输出参数)
as
declare @TmpSelect NVarchar(4000)
declare @Tmp NVarchar(4000)
declare @pagecount int
set nocount on--关闭计数
set @RecordCount=0
set @TmpSelect = 'select @RecordCount=count(*) from '+@TableName+' where '+@SelectWhere
execute sp_executesql
@TmpSelect, --执行上面的sql语句
N'@RecordCount int OUTPUT' , --执行输出数据的sql语句,output出总记录数
@RecordCount OUTPUT
if (@RecordCount = 0) --如果没有贴子,则返回零
return 0
set @pagecount = @RecordCount/@intPageSize
if(@RecordCount%@intPageSize>0)
set @pagecount=@pagecount+1
if(@pagecount<=0)
set @pagecount=1
if(@intPageNo>@pagecount)
set @intPageNo=@pagecount
/*判断页数是否正确*/
--if (@intPageNo - 1) * @intPageSize > @RecordCount --页号大于总页数,返回错误
--set @intPageNo=@pagecount
set nocount off--打开计数
if @SelectWhere != ''
begin
set @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' where '+@SelectOrderId+' not in(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+' where '+@SelectWhere +' '+@SelectOrder+') and '+@SelectWhere +' '+@SelectOrder
end
else
begin
set @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' where '+@SelectOrderId+' not in(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+''+@SelectOrder+') '+@SelectOrder
end
execute sp_executesql @TmpSelect
return(@@rowcount)
GO
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |