Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

TOP 100 PERCENT - Why?

 
   Database Help (Home) -> Programming RSS
Next:  how do I create an authorized signers database in..  
Author Message
Jordan S.

External


Since: May 30, 2008
Posts: 7



(Msg. 1) Posted: Wed Dec 03, 2008 10:43 am
Post subject: TOP 100 PERCENT - Why?
Archived from groups: microsoft>public>sqlserver>programming (more info?)

I just found this query in a legacy datase.

When, if ever, does "TOP 100 PERCENT" ever make sense? Why do it?

SELECT TOP 100 PERCENT LastName FROM
(
SELECT LastName FROM People1
UNION
SELECT LastName FROM People2
) Alias
ORDER BY 1

 >> Stay informed about: TOP 100 PERCENT - Why? 
Back to top
Login to vote
Kalen Delaney

External


Since: Oct 27, 2003
Posts: 289



(Msg. 2) Posted: Wed Dec 03, 2008 11:51 am
Post subject: Re: TOP 100 PERCENT - Why? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi Jordan

It used to be that you could impose ordering on a view in you had a TOP
clause. Normally, ORDER BY in a view is not allowed. But with TOP, you could
do it, and with TOP 100 PERCENT you could get all the rows ordered.

That's the only reason it ever made sense, if you call imposing order on an
unordered set "sense".

--
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
www.SQLTuners.com


"Jordan S." <A.DeleteThis@B.com> wrote in message
news:OJ4NZcXVJHA.3708@TK2MSFTNGP03.phx.gbl...
>I just found this query in a legacy datase.
>
> When, if ever, does "TOP 100 PERCENT" ever make sense? Why do it?
>
> SELECT TOP 100 PERCENT LastName FROM
> (
> SELECT LastName FROM People1
> UNION
> SELECT LastName FROM People2
> ) Alias
> ORDER BY 1
>
>

 >> Stay informed about: TOP 100 PERCENT - Why? 
Back to top
Login to vote
Scott Morris

External


Since: Aug 28, 2003
Posts: 82



(Msg. 3) Posted: Wed Dec 03, 2008 2:26 pm
Post subject: Re: TOP 100 PERCENT - Why? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Jordan S." <A.DeleteThis@B.com> wrote in message
news:OJ4NZcXVJHA.3708@TK2MSFTNGP03.phx.gbl...
>I just found this query in a legacy datase.
>
> When, if ever, does "TOP 100 PERCENT" ever make sense? Why do it?

Never. However, the query engine is usually smart enough to ignore the top
directive in such cases.
 >> Stay informed about: TOP 100 PERCENT - Why? 
Back to top
Login to vote
steve

External


Since: Dec 03, 2008
Posts: 1



(Msg. 4) Posted: Wed Dec 03, 2008 4:25 pm
Post subject: Re: TOP 100 PERCENT - Why? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

This is standard practice if you're using SQL Views, because you can't sort
them, if you try it tells you it can only be sorted if using top.

So by doing a top 100 percent you sort the whole table.... its silly but
those are the rules.

Steve



"Jordan S." <A RemoveThis @B.com> wrote in message
news:OJ4NZcXVJHA.3708@TK2MSFTNGP03.phx.gbl...
>I just found this query in a legacy datase.
>
> When, if ever, does "TOP 100 PERCENT" ever make sense? Why do it?
>
> SELECT TOP 100 PERCENT LastName FROM
> (
> SELECT LastName FROM People1
> UNION
> SELECT LastName FROM People2
> ) Alias
> ORDER BY 1
>
>
 >> Stay informed about: TOP 100 PERCENT - Why? 
Back to top
Login to vote
David Portas1

External


Since: Aug 26, 2004
Posts: 37



(Msg. 5) Posted: Wed Dec 03, 2008 11:26 pm
Post subject: Re: TOP 100 PERCENT - Why? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 3 Dec, 20:43, "steve" <steve_le... DeleteThis @nospam.hotmail.com> wrote:
> This is standard practice if you're using SQL Views, because you can't sort
> them, if you try it tells you it can only be sorted if using top.
>
> So by doing a top 100 percent you sort the whole table.... its silly but
> those are the rules.
>

Not silly at all. The silly thing is to assume that by using TOP 100
PERCENT in a view you will determine the ordering of some other query
without ORDER BY that uses the view. That assumption is incorrect
because the ordering of any other query *without* the ORDER BY clause
is undefined - even if it uses a view that contains ORDER BY.
Therefore it never makes sense to use TOP 100 PERCENT... ORDER BY in a
view.

Microsoft is partly to blame for this confusion because they invented
the daft "TOP" syntax, which assigns a double meaning to the ORDER BY
clause. ORDER BY is used in views only to select the subset of rows
required by the TOP clause. It has nothing to do with ordering the
results of queries that use the view.

--
David Portas
 >> Stay informed about: TOP 100 PERCENT - Why? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Calculating Percent - I get zero when I do this calculation and I need help. I want to calculate the percent of employees that have been evaluated against total number of employees. I tried this COUNT(Evaluated_.Employees) / Total_Number_Employees So Evaluated employees =....

Help with SELECT TOP PERCENT. - Hi, I have the following SP:- @cleaning_team as varchar(1), @team as varchar(1), @sub_team as tinyint, @top as int AS SELECT TOP 10 PERCENT dbo.vw_supervisor_inspection_jetspray_pre_post.*, CLEANING_TEAM_PRE, TEAM_PRE, SUB_TEAM_PRE,..

Select top 100 percent - why does this work? - We have an asp.net application that was working fine on Windows 2003 / SQL server 2000. When one of our servers was upgraded to SQL 2005 we noticed that some of the stored procedures were causing the application to time out. The SPs run within 2 second...

need help with query - I want to sum the records in a table (u) which have 'P.M.' in a field value and test against a fixed limit something to the effect of : case when SUM(substring(u.sTime,1,4)='P.M.') &lt;= 64 Then .... except it should work ...

Next?? - I have a field stored as NTEXT(16). I need to replace some of the content in this field. I know the replace function doesnt work. I see there is UPDATETEXT - is this the ONLY way to do it ?? 'cos it looks quite complicated? thanks, Justin
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]