存储中如何传递如下参数:select top (参数1) id from mytable

叶子哟 2003-01-08 09:48:21
参数1为一整数参数,为何不行
...全文
75 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
glboy 2003-01-08
  • 打赏
  • 举报
回复
create procedure myproc1 @myint int
as
exec ('select top ' + str(@myint) + ' * from allquestion')

不是可以了吗?加上str函数就可以声明为int啊
叶子哟 2003-01-08
  • 打赏
  • 举报
回复
唉,必须声明@myint 为类char型,已解决!!
叶子哟 2003-01-08
  • 打赏
  • 举报
回复
创建可以了,但运行时报错!
create procedure myproc1 @myint int
as
exec ('select top ' + @myint + ' * from allquestion')
pengdali 2003-01-08
  • 打赏
  • 举报
回复
declare @i
set @i=10
exec ('select top '+@i+ ' * from 表')
hjhing 2003-01-08
  • 打赏
  • 举报
回复
exec ('select top '+ @int + ' [id] from myTable')

34,837

社区成员

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

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