C# Help with Substring - Need to return just the WHERE clause of SQL Statement

I have 100's of SQL statements.. I need a function to return just the WHERE portion of the SQL statement - Each Statement has an ORDER at the end which I don't need

SELECT * FROM EMPLOYEES WHERE EMPLOYEE.LAST_NAME = 'JONES' ORDER BY LAST_NAME

           "EMPLOYEE.LAST_NAME = 'JONES'"

SELECT * FROM CUSTOMERS WHERE CUSTOMER.NAME = 'Abc' AND CUSTOMER.NUMBER > 101  ORDER BY CUSTOMER.NUMBER  

   "CUSTOMER.NAME = 'Abc' AND CUSTOMER.NUMBER > 101"    


Select rtrim(lastname)+', '+rtrim(firstname) as Name, * from cUSTOMER where (Inactive =' '  And  RepNo <  'P00001 '   And   CurrentYear = ' '  And  FutureTermination = ' '  and deleted = 0) order by lastname, firstname  

 "(Inactive =' '  And  RepNo <  'P00001 '   And   CurrentYear = ' '  And  FutureTermination = ' '  and deleted = 0)


Needs to also consider the case of 'WHERE' and 'ORDER'

Thanks
LVL 1
JElsterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ryerrasCommented:
i do not understand. The following statements are contradictory

----- Each Statement has an ORDER at the end which I don't need
----- Needs to also consider the case of 'WHERE' and 'ORDER'
Let us know what you are looking for
0
JElsterAuthor Commented:
Just need the where part ,not the order by... Some of the statements are in upper case and others not..

For Example:

SELECT * FROM EMPLOYEES WHERE EMPLOYEE.LAST_NAME = 'JONES' ORDER BY LAST_NAME


I just need return the following:

           "EMPLOYEE.LAST_NAME = 'JONES'"
0
ryerrasCommented:
lets say

string str = "SELECT * FROM EMPLOYEES WHERE EMPLOYEE.LAST_NAME = 'JONES' ORDER BY LAST_NAME" ;

int x = str.IndexOf("WHERE");
if(x == -1)
 x = str.IndexOf("where");
int y = str.IndexOf("ORDER");
 if(y== -1)
 y=str.IndexOf("order");

string subString = str.Substring(x + 5, y - x - 5);

this works
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.