select 问题

happyie 2007-03-15 02:21:33
declare @count int
set @count = 2
select top @count * from test

这句话为什么出错
...全文
226 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
areswang 2007-03-16
  • 打赏
  • 举报
回复
mark
saiwong 2007-03-16
  • 打赏
  • 举报
回复
动态的sql
mugua604 2007-03-16
  • 打赏
  • 举报
回复
2005 top 可以带参
wojila 2007-03-16
  • 打赏
  • 举报
回复
declare @n int set @n=4
exec('select top '+ @n+' * from tb1')
happyie 2007-03-15
  • 打赏
  • 举报
回复
declare @count int
set @count = 2

DECLARE csrCmd CURSOR LOCAL FOR
exec('select top '+ @count + ' * from test')
OPEN csrCmd
FETCH csrCmd INTO @filmid

我需要在存储过程中 ,好像这样还是不行
leo_lesley 2007-03-15
  • 打赏
  • 举报
回复
select top @count * from test

这个语句不能直接执行,要变成动态的sql执行
冷箫轻笛 2007-03-15
  • 打赏
  • 举报
回复
2005没问题

2000就会出错

declare @count int
set @count = 2
exec('select top '+ cast(@count as varchar) + ' * from test')
leo_lesley 2007-03-15
  • 打赏
  • 举报
回复
------------try-------------

declare @count int
set @count = 2
exec('select top '+@count+' * from test')

34,588

社区成员

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

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