新聞中心
SQL Server數(shù)據(jù)庫查詢時,能否按百分比查詢出記錄的條數(shù)呢?答案是肯定的。本文我們就介紹這一實現(xiàn)方法。

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比鄯善網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式鄯善網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋鄯善地區(qū)。費用合理售后完善,十余年實體公司更值得信賴。
實現(xiàn)該功能的代碼如下:
- create procedure pro_topPercent
- (
- @ipercent [int] =0 --默認(rèn)不返回
- )
- 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' --執(zhí)行存儲過程
創(chuàng)建存儲過程的語法類似帶指針的C#,創(chuàng)建時參數(shù)表用小括號括起,輸出參數(shù)帶傳遞方向的參數(shù)標(biāo)識 OUTPUT,輸入?yún)?shù)不用,參數(shù)聲明格式:
(
@studentname [nvarchar] (50) output
)
存儲過程執(zhí)行時參數(shù)表不用加括號,若有輸出參數(shù),先聲明,用如下格式執(zhí)行:
- declare @studentname_1
- exec myprocedure
'輸入?yún)?shù)',@studentname_1 output, 如果前臺用的是.net的話可以在comand.parameters中添加傳遞方向為output的sqlparameter參數(shù)接收該值。
關(guān)于SQL Server數(shù)據(jù)庫按百分比查詢記錄條數(shù)的操作就介紹到這里,希望本次的介紹能夠給您帶來一些收獲,謝謝!
網(wǎng)站名稱:SQLServer數(shù)據(jù)庫如何按百分比查詢出表中的記錄數(shù)
當(dāng)前地址:http://m.fisionsoft.com.cn/article/cdejjhc.html


咨詢
建站咨詢
