欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SQL Server數(shù)據(jù)庫(kù)按百分比查詢出表中的記錄數(shù)

 更新時(shí)間:2015年08月18日 11:36:59   投稿:lijiao  
這篇文章主要介紹了SQL Server數(shù)據(jù)庫(kù)在一個(gè)表中按百分比查詢出記錄條數(shù)的方法及代碼示例,需要的朋友可以參考下

SQL Server數(shù)據(jù)庫(kù)查詢時(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í)行存儲(chǔ)過(guò)程

創(chuàng)建存儲(chǔ)過(guò)程的語(yǔ)法類似帶指針的C#,創(chuàng)建時(shí)參數(shù)表用小括號(hào)括起,輸出參數(shù)帶傳遞方向的參數(shù)標(biāo)識(shí) OUTPUT,輸入?yún)?shù)不用,參數(shù)聲明格式:

@studentname  [nvarchar] (50)   output

存儲(chǔ)過(guò)程執(zhí)行時(shí)參數(shù)表不用加括號(hào),若有輸出參數(shù),先聲明,用如下格式執(zhí)行:

declare @studentname_1 
 
exec myprocedure 

'輸入?yún)?shù)',@studentname_1 output, 如果前臺(tái)用的是.net的話可以在comand.parameters中添加傳遞方向?yàn)閛utput的sqlparameter參數(shù)接收該值。

關(guān)于SQL Server數(shù)據(jù)庫(kù)按百分比查詢記錄條數(shù)的操作就介紹到這里,希望本次的介紹能夠給您帶來(lái)一些收獲。

相關(guān)文章

最新評(píng)論