马可大哥在吗?我在SQL语句中用变量还是不行啊,我也看了你那篇"[交流]动态SQL语句"!!!

jueduiweiyi 2003-12-01 11:04:54
我是在一个存储过程中用变量:
create proc fenye
@intDays int ,
@pagesize tinyint,
@pageno int,
@tnames varchar,
@tfield varchar,
@tvalues int
as
declare @RecordNumber int
declare @StartRecord int
select @RecordNumber = @pagesize*@pageno
select @StartRecord=@pagesize*(@pageno-1)+1
begin
select "RecordCount"=count(*) from dinfo
set rowcount @RecordNumber
declare curfenye Scroll Cursor
for
exec sp_executesql N 'select * from '+@tnames+' where '+@tfield+'='+@tvalues+' order by ID desc'
open curfenye
fetch absolute @StartRecord from curfenye
while @@fetch_status = 0
fetch next from curfenye
set rowcount 0
/*清场*/
CLOSE curfenye
DEALLOCATE curfenye
end
GO
报错是在for下面的那一行:
错误156:关键字exec附近有语法错误
第18行,在select * from附近有语法错误!
...全文
31 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 元老 2003-12-01
  • 打赏
  • 举报
回复
create proc fenye
@intDays int ,
@pagesize tinyint,
@pageno int,
@tnames varchar,
@tfield varchar,
@tvalues int
as
declare @RecordNumber int
declare @StartRecord int

select @RecordNumber = @pagesize*@pageno
select @StartRecord=@pagesize*(@pageno-1)+1
begin
select "RecordCount"=count(*) from dinfo
set rowcount @RecordNumber
exec('declare curfenye Scroll Cursor
for select * from '+@tnames+' where '+@tfield+'='+@tvalues+' order by ID desc' )
open curfenye
fetch absolute @StartRecord from curfenye
while @@fetch_status = 0
fetch next from curfenye
set rowcount 0
/*清场*/
CLOSE curfenye
DEALLOCATE curfenye
end
GO
jueduiweiyi 2003-12-01
  • 打赏
  • 举报
回复
马可大哥,今天去哪里啦
jueduiweiyi 2003-12-01
  • 打赏
  • 举报
回复
哈哈
谢谢邹建大哥!!!

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧