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.
| 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 LCTas SELECT TOP (100) PERCENT d.stk_cd AS StockCode, d.whse AS Warehouse, SUM(d.ord_qty - d.recd_qty) AS OnOrderLCTFROM HDR AS h INNER JOIN DETL AS d ON h.prchse_ord = d.prchse_ordWHERE (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.whseORDER 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 Viewie if you want results ordered you need to explictly include in select statement of view see below link for more detailshttp://visakhm.blogspot.com/2010/01/behaviour-of-order-by-inside-view.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|