问题描述
您好,所有专家,
我想在sql server 2008 R2中显示前10,20或8.
我这样宣告:
声明@top int
设置@ top = 4
设置行数@top
选择top @top ItemCode,ItemName
来自项目
但它不起作用,并显示如下错误:
"@top"附近的语法不正确."
注意:
-variable @top是动态值,并基于用户输入.
-我不想使用rowcount @top coz,这会使我的查询变慢.
有人知道我如何在sql server 2008R2中使用top @top吗?
谢谢
TONY
Hi all experts,
i want to display top 10,20 or 8 in sql server 2008 R2.
i declare like this:
declare @top int
set @top=4
set rowcount @top
select top @top ItemCode,ItemName
from item
but it doesn''t work and it display an error like this:
"Incorrect syntax near ''@top''."
Note:
-variable @top is a dynamic value and based on user inputted.
-I don''t want to use rowcount @top coz it make my query slow.
Does anybody know how i can work with top @top in sql server 2008R2?
Thanks
TONY
推荐答案
declare @top int
set @top=4
select top (@top) ItemCode,ItemName
from item
这篇关于从项目中选择top @top ItemCode,ItemName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!