从项目中选择top @top ItemCode,ItemName [英] select top @top ItemCode,ItemName from item

查看:145
本文介绍了从项目中选择top @top ItemCode,ItemName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,所有专家,

我想在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

推荐答案

阅读以下内容:
Read the following : http://stackoverflow.com/questions/175962/dynamic-select-top-var-in-sql-server[^]


应将其括在( ).

试试这个.

It should be enclosed in ().

try this.

declare @top int
set @top=4
select top (@top) ItemCode,ItemName
from item


这篇关于从项目中选择top @top ItemCode,ItemName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆