SQL Server数据库按百分比查询出表中的记录数

栏目: 数据库 · SQL Server · 发布时间: 7年前

内容简介:这篇文章主要介绍了SQL Server数据库在一个表中按百分比查询出记录条数的方法及代码示例,需要的朋友可以参考下

SQL Server 数据库查询时,能否按百分比查询出记录的条数呢?答案是肯定的。本文我们就介绍这一实现方法。

实现该功能的代码如下:

create procedure pro_topPercent  
( 
 @ipercent [int] =0        --默认不返回 
) 
as 
begin 
select top (@ipercent ) percent * from books 
end 

create procedure pro_topPercent  
( 
 @ipercent [int] =0  
) 
as 
begin 
select top((select COUNT (*) from books)*(@ipercent)/100) * from books 
end 
exec pro_topPercent '10'    --执行存储过程

创建存储过程的语法类似带指针的C#,创建时参数表用小括号括起,输出参数带传递方向的参数标识 OUTPUT,输入参数不用,参数声明格式:

(

@studentname  [nvarchar] (50)   output

)

存储过程执行时参数表不用加括号,若有输出参数,先声明,用如下格式执行:

declare @studentname_1 
 
exec myprocedure 

'输入参数',@studentname_1 output,如果前台用的是.net的话可以在comand.parameters中添加传递方向为output的sqlparameter参数接收该值。


以上所述就是小编给大家介绍的《SQL Server数据库按百分比查询出表中的记录数》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Letting Go of the Words

Letting Go of the Words

Janice (Ginny) Redish / Morgan Kaufmann / 2007-06-11 / USD 49.95

"Redish has done her homework and created a thorough overview of the issues in writing for the Web. Ironically, I must recommend that you read her every word so that you can find out why your customer......一起来看看 《Letting Go of the Words》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

html转js在线工具
html转js在线工具

html转js在线工具