[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

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
0
JElster
Asked:
JElster
  • 2
1 Solution
 
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now