如何在SQL Server中获取colum值 [英] How to get colum values in SQL server

查看:92
本文介绍了如何在SQL Server中获取colum值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sql server中有一个包含15条记录的列。在那15条记录中,我希望例如显示10条记录,之后在按钮点击后显示5条记录,如创建引导标签面板。



我的尝试:



查询:

从表组中选择列名按列名按顺序排列asc



在c#asp.net中使用此查询我得到15一次记录....我怎样才能实现这个目标

I am having a column in sql server with 15 records. In that 15 records I want for example 10 records to be displayed and later on 5 records should be displayed after button click like creating a bootstrap tab panel.

What I have tried:

Query:
select columnname from table group by columnname order by number asc

With this query in c# asp.net I am getting 15 records at a time.... How can I achieve this goal

推荐答案

这有两个部分:获得10个项目非常简单,只需使用TOP:

There are two parts to this: getting ten items is pretty easy, just use TOP:
SELECT TOP 10 columnname FROM table ORDER BY number asc

请注意,您不能使用示例中的GROUP BY子句,因为如果您这样做除非该列出现在GROUP BY子句中,否则不能使用ORDER BY。这可能有所帮助: SQL GROUP By和列'名称'在选择列表中无效,因为......错误 [ ^ ]



获取接下来的十个更复杂:

Note that you can't use the GROUP BY clause of your example, because if you do you can't use ORDER BY unless that column appears in the GROUP BY clause. This may help: SQL GROUP By and the "Column 'name' is invalid in the select list because..." error[^]

Getting the next ten is more complex:

SELECT columnname FROM 
 (SELECT ROW_NUMBER() OVER (ORDER BY columnname ASC) AS RN, columnname FROM table GROUP BY columnname) j
WHERE RN BETWEEN 11 AND 20


您正在寻找的概念称为寻呼。



以下是CodeProject文章,它们将帮助

ASP中的ADO Recordset分页 [ ^ ]

ASP.NET分页 [ ^ ]

< a href =https://www.codeproject.com/Articles/1078662/How-to-implement-Paging-in-ASP-NET-at-SQL-Query-Le>如何在ASP.NET中实现分页SQL查询级别 [ ^ ]
The concept you are looking for is called "Paging".

Here are CodeProject articles that will help
ADO Recordset Paging in ASP[^]
ASP.NET Pagination[^]
How to implement Paging in ASP.NET at SQL Query Level[^]


这篇关于如何在SQL Server中获取colum值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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