2

I need to parse SQL to get all:

  • Table names after INSERT clause,
  • Tables after FROM, JOINs (including CROSS JOIN as comma ',' operator) clauses,
  • The same with OPENQUERY or any other subqueries.

Each statement is one-liner SQL, without any extra spaces, comments, or new lines. Each query is INSERT-statement.

I have almost working regex: https://regex101.com/r/iS2fK9/1.

But it has a problem: regex cathes only first FROM/JOIN statement. Or only last if I apply greedy quantificators.

Ideal result is syntax tree. But simple list of named group will be sufficient.

  • possible duplicate of [Parsing SQL code in C#](http://stackoverflow.com/questions/589096/parsing-sql-code-in-c-sharp) – Sam Axe Aug 04 '15 at 22:29
  • Instead of regex, consider a T-SQL parser: https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.transactsql.scriptdom.aspx – Dan Guzman Aug 05 '15 at 02:54

0 Answers0