0

I've never heard of PERCENT but according tgo http://technet.microsoft.com/en-us/library/ms189463.aspx the PERCENT can be used with TOP to return a percentage of the records.

I am working on a function with this in it:

SELECT top 100 percent

Am I right in thinking this is exactly the same as

SELECT
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
DavidB
  • 2,566
  • 3
  • 33
  • 63
  • 3
    Very brief answer: **Yes**, you're correct – marc_s Oct 30 '13 at 09:36
  • 3
    Yes, doesn't do anything. It's often used as a hack to put in an order by where there shouldn't be one (e.g. a view). – Bridge Oct 30 '13 at 09:37
  • Thanks, Ill remove this code then as its unnecessary – DavidB Oct 30 '13 at 09:37
  • The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified. -- Looks like you were right bridge – DavidB Oct 30 '13 at 09:38
  • 1
    Related/Duplicate(?): [Why use Select Top 100 Percent?](http://stackoverflow.com/questions/1622878/why-use-select-top-100-percent) – Tim Schmelter Oct 30 '13 at 09:38
  • I have heard of it used to force a CTE to materialize but only a comment. – paparazzo Oct 30 '13 at 10:02
  • @Bridge, `top 100 percent` doesn't do that any more in later versions of SQL server.... you have to use `TOP 999999999999` to achieve that instead... – Ben Oct 30 '13 at 11:28
  • Don't like to contradict you @Ben, but `top 100 percent` works in every version of SQL server I've used (from 6.5 through to SQL Azure). – dav1dsm1th Oct 30 '13 at 18:19
  • @dav1dsm1th, it happened to me, I don't recall what the issue was exactly. Either a view or subquery or inline function? Something didn't work with top 100 percent but changing it to top 9999999999999 did... Just putting it out there. – Ben Oct 30 '13 at 19:20

0 Answers0