Specify the number of records to be retrieved as a percentage

Page update date :
Page creation date :

If you want to get the "top N" among the number of records to be fetched, you can use the "TOP clause", but you can also get this number as a percentage. TO GET BY A PERCENTAGE, USE "TOP - PERCENT".

An example of selecting a table with 10,000 records. If you do not use the TOP clause, 10,000 records are retrieved.

select * from [TST_Tag01]

TOP 句を使用しない SELECT

The following example retrieves the number specified in the TOP clause.

select top 200 * from [TST_Tag01]

TOP 句を使用した SELECT

The following example retrieves the number of counts specified by PERCENT in the TOP clause. If you specify 40, you are getting 40% of the records.

select top (40) percent * from [TST_Tag01]

TOP 句に PERCENT を使用した SELECT

PERCENT can also contain decimal numbers.

select top (3.5) percent * from [TST_Tag01]

TOP 句に小数を含む PERCENT を使用した SELECT

The number that can be specified for PERCENT can be 0 ~ 100.

Also, if you use PERCENT, enclose the number in parentheses "()". This is for compatibility reasons, but be sure to use parentheses because not enclosing them in parentheses may result in errors.