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
 General SQL Server Forums
 New to SQL Server Programming
 top (100) percent

Author  Topic 

bigben
Starting Member

1 Post

Posted - 2012-02-10 : 15:59:55
I got this code from someone and I don't understand why top 100 percent is used. I ran it and it's not recognized in pl sql. Can someone help? Thanks.

create view as LCT
as SELECT TOP (100) PERCENT d.stk_cd AS StockCode, d.whse AS Warehouse,
SUM(d.ord_qty - d.recd_qty) AS OnOrderLCT
FROM HDR AS h INNER JOIN
DETL AS d ON h.prchse_ord = d.prchse_ord
WHERE (d.lst_confmd = 'Y') AND (h.cncl_flg <> 'Y') AND (h.actv_flg <> 'N') AND (d.cmplt_flg <> 'Y')
GROUP BY d.stk_cd, d.whse
ORDER BY StockCode, Warehouse

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-10 : 16:03:29
its used just for introducing the ORDER BY. you cant use ORDER BY inside view without including TOP clause.
Actually it doesnt make any sense to add ORDER BY and TOP 100 PERCENT inside a view as it will not guarantee the order or results if you just use
SELECT * FROM View
ie if you want results ordered you need to explictly include in select statement of view

see below link for more details

http://visakhm.blogspot.com/2010/01/behaviour-of-order-by-inside-view.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -