Friday, 19 April 2013

Use of percent(%) in Top command in SQL Server

Written By:- Isha Malhotra
Our Website:-Tech Altum

Use of percent(%) in Top command in SQL Server

In my last article I discussed about the top command. In this article I am showing how to use percent with top command. I am taking the table same as I used in my last article.

Use of percent in Top command

 If I Want to select 2 rows from the top then I will write the following query:-

select top 2 * from prod_rep

But we can also select Data in percentage (%) using top command. Using percentage it will show the row Accordingly. For example if table contains 4 rows and I select 50% then it will Show 2 rows.

For example:-

Take the following Table to show this example:-

Figure 1

This table contain the 8 rows and I run the following queries using top command:-

select top 50percent *  from prod_rep;

it will show the following output:-

Figure 2

According to the percentage which you will Give in the query it will show the output.