SQL Server数据库按百分比查询出表中的记录数
SQLServer数据库查询时,能否按百分比查询出记录的条数呢?答案是肯定的。本文我们就介绍这一实现方法。
实现该功能的代码如下:
createprocedurepro_topPercent ( @ipercent[int]=0--默认不返回 ) as begin selecttop(@ipercent)percent*frombooks end
或
createprocedurepro_topPercent ( @ipercent[int]=0 ) as begin selecttop((selectCOUNT(*)frombooks)*(@ipercent)/100)*frombooks end execpro_topPercent'10'--执行存储过程
创建存储过程的语法类似带指针的C#,创建时参数表用小括号括起,输出参数带传递方向的参数标识OUTPUT,输入参数不用,参数声明格式:
(
@studentname [nvarchar](50) output
)
存储过程执行时参数表不用加括号,若有输出参数,先声明,用如下格式执行:
declare@studentname_1 execmyprocedure
'输入参数',@studentname_1output,如果前台用的是.net的话可以在comand.parameters中添加传递方向为output的sqlparameter参数接收该值。
关于SQLServer数据库按百分比查询记录条数的操作就介绍到这里,希望本次的介绍能够给您带来一些收获。