it would be perhaps easier to separate the sql
statement into a string list of all individual
words.
SELECT Company, OrderNumber FROM Orders
ORDER BY Company
becomes a list
SELECT
Company,
OrderNumber
FROM
Orders
ORDER
BY
Company
then based upon a list of rules you can determine if
the word following the first word is legitimate or not.
and so on
tomcruz.net