SQL Server數(shù)據(jù)庫按百分比查詢出表中的記錄數(shù)
SQL Server數(shù)據(jù)庫查詢時(shí),能否按百分比查詢出記錄的條數(shù)呢?答案是肯定的。本文我們就介紹這一實(shí)現(xiàn)方法。
實(shí)現(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ù)帶傳遞方向的參數(shù)標(biāo)識 OUTPUT,輸入?yún)?shù)不用,參數(shù)聲明格式:
(
@studentname [nvarchar] (50) output
)
存儲過程執(zhí)行時(shí)參數(shù)表不用加括號,若有輸出參數(shù),先聲明,用如下格式執(zhí)行:
declare @studentname_1 exec myprocedure
'輸入?yún)?shù)',@studentname_1 output, 如果前臺用的是.net的話可以在comand.parameters中添加傳遞方向?yàn)閛utput的sqlparameter參數(shù)接收該值。
關(guān)于SQL Server數(shù)據(jù)庫按百分比查詢記錄條數(shù)的操作就介紹到這里,希望本次的介紹能夠給您帶來一些收獲。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信