Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Problem in TOP(n) Percent

Author  Topic 

chandru_zylog
Starting Member

4 Posts

Posted - 2008-03-20 : 03:31:23
hai everybody,

i have doubt With the Top(n) percent keyword
for example consider the table employee with following details i'm using a query

SELECT TOP(19) PERCENT * FROM Employee

if i execute this query im gettin 2 record set whose id is less than
6

SELECT TOP(19) PERCENT * FROM Employee WHERE ID <6

like wise if i execute the above query i'm gettin only one record set instead of two record set ...

why so, can anyone help me on this??...


id name salary st_date city region
1 Jason 40420 1994-02-01 00:00:00.000 New York W
2 Robert 14420 1995-01-02 00:00:00.000 Vancouver N
3 Celia 24020 1996-12-03 00:00:00.000 Toronto W
4 Linda 40620 1997-11-04 00:00:00.000 New York N
5 David 80026 1998-10-05 00:00:00.000 Vancouver W
6 James 70060 1999-09-06 00:00:00.000 Toronto N
7 Alison 90620 2000-08-07 00:00:00.000 New York W
8 Chris 26020 2001-07-08 00:00:00.000 Vancouver N
9 Mary 60020 2002-06-09 00:00:00.000 Toronto W

Thanks in Advance

Koji Matsumura
Posting Yak Master

141 Posts

Posted - 2008-03-20 : 03:45:39
9 * 0.19 = 1.71 --> 2 records
5 * 0.19 = 0.95 --> 1 record
Go to Top of Page

jrogers
Starting Member

34 Posts

Posted - 2008-03-20 : 03:46:48
19% of 9records is 1.71 so you get 2 records
19% of 5 is 0.95 so you get 1 record.. are you trying to produce the top 19% of salary
Go to Top of Page

chandru_zylog
Starting Member

4 Posts

Posted - 2008-03-20 : 04:40:22
Thanks for your response and now im clear about that.
Go to Top of Page
   

- Advertisement -