Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SELE .... UNION problem
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00846041
Message ID:
00846046
Views:
21
This message has been marked as the solution to the initial question of the thread.
Randy,

The ORDER BY clause can only by applied to the whole select (result of UNION) not to each individual SELECT. You can get the same result w/o UNION also.
SELECT "1" AS so, *  FROM bondmat ;
	WHERE stores  ;
	UNION ALL ;
		SELECT "2" AS so, *  FROM bondmat ;
		WHERE .NOT.stores  
        ORDER BY part_no ;
	INTO TABLE rcursor
* W/o UNION
SELECT IIF(stores, "1", "2") AS so, *  ;
        FROM bondmat ;
        ORDER BY part_no ;
	INTO TABLE rcursor
>Hello All,
>
>Using VFP7 SP1. In an attempt to build a report cursor, I wrote the following SQL SELECT statement: (bondmat is C10, stores is L1)
>
>SELECT "1" AS so, *  FROM bondmat ;
>	WHERE stores  ORDER BY part_no ;
>	UNION ALL ;
>		SELECT "2" AS so, *  FROM bondmat ;
>		WHERE .NOT.stores  ORDER BY part_no ;
>	INTO TABLE rcursor
>
>The two halves work fine independently of each other, but the attempt to 'stik'em' together gives me the message 'Order By clause is invalid'.
>
>The easy out for this situation was to add a new index to the table, but I'm still curious about what I did wrong in the SELECT.
>
>Thanks,
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform