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 2000 Forums
 Transact-SQL (2000)
 Order By in Union View is ignored

Author  Topic 

Ken Blum
Constraint Violating Yak Guru

383 Posts

Posted - 2004-12-28 : 12:24:23
I run the following in QA without any problems. It's combining a table and another view via a Union. However when I run it as a View, it does not sort by ABALPH. How come?


CREATE VIEW dbo.Lab_Customers
AS
SELECT TOP 100 PERCENT ABALPH AS CustomerName, ABMCU AS Location, ABAN8 AS CustomerNo
FROM PRODDTA.F0101
WHERE (ABAT1 = 'CS')

UNION

SELECT TOP 100 PERCENT Description AS ABALPH, MarketSegment AS Location, CAST(MarketSegment AS FLOAT) AS CustomerNo
FROM dbo.MarketSegments

ORDER BY ABALPH

TIA,

nr
SQLTeam MVY

12543 Posts

Posted - 2004-12-28 : 12:29:30
It does't always honour it.
try this -
SELECT TOP 100 PERCENT *
from
(
ABALPH AS CustomerName, ABMCU AS Location, ABAN8 AS CustomerNo
FROM PRODDTA.F0101
WHERE (ABAT1 = 'CS')
UNION
SELECT Description AS ABALPH, MarketSegment AS Location, CAST(MarketSegment AS FLOAT) AS CustomerNo
FROM dbo.MarketSegments
) a
ORDER BY CustomerName


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Ken Blum
Constraint Violating Yak Guru

383 Posts

Posted - 2004-12-28 : 12:43:28
That did it. Thanks.
Go to Top of Page
   

- Advertisement -