troubleshooting Question

Need a Regex to extract the correct FROM clause

Avatar of Russ Suter
Russ Suter asked on
Regular Expressions.NET ProgrammingC#
4 Comments1 Solution62 ViewsLast Modified:
I'm looking for a Regex that will allow me to select the appropriate FROM clause in a SQL SELECT statement. I'm looking for the FROM clause for the outermost SELECT statement only. The example below shows in bold what I mean. This query, although fairly crappy as a SQL query, fairly well demonstrates what I mean. You can see that there are 3 separate FROM clauses. I can't always rely upon it being first because of the inline query in the SELECT clause. I can't always rely on it being last because of the subquery in the WHERE clause. The one thing I can know for certain is that there will be a 1 to 1 relationship between the SELECT and FROM keywords. I need my Regex to EXACTLY and ONLY match the FROM keyword associated with the outermost query.

      (SELECT SUM([Amount]) FROM [Invoices])
      [InvoiceNumber] NOT IN
            [TimeStamp] BETWEEN '1/1/2019' AND '12/31/2019'
Senior Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros