When querying a SQL Server database, can you query the number of records by percentage? The answer is yes. This article we introduce this implementation method.
The code to implement this feature is as follows:
CREATE PROCEDURE Pro_toppercent
(
@ipercent [int] =0 --default does not return
) as
begin select Top
(@ Ipercent) percent * from books
Or
CREATE PROCEDURE Pro_toppercent
(
@ipercent [int] =0
)
as
begin
Select Top (select COUNT (*) from Books) * (@ipercent)/100) * "From books end
exec pro_toppercent '"- Execute stored procedure
The syntax for creating stored procedures is similar to C # with pointers, when the parameter table is created with parentheses, output parameters are marked with the direction of transmission, input parameters are not used, parameter declaration format:
(
@studentname [nvarchar] (output)
)
The parameter table is not enclosed in parentheses when the stored procedure executes, and if there is an output parameter, it is declared first and executed in the following format:
DECLARE @studentname_1
exec myprocedure
' Input parameters ', @studentname_1 output, if the foreground is using. NET, you can add a delivery direction to an output SqlParameter parameter in Comand.parameters to receive the value.
About the SQL Server database to query the percentage of the number of records to the operation of the article here, I hope this introduction can bring you some harvest.