SQL Parsing in C#?
Irony for C# has an LALR parser with several grammars already created, including one for SQL (as you can see from the screenshot on the home page). It's a very easy to use parser using operator overloads to define the grammars in a way reminiscent to BNF.
Parsing SQL code in C#
[Warning: answer may no longer apply as of 2021]
Use Microsoft Entity Framework (EF).
It has a "Entity SQL" parser which builds an expression tree,
using System.Data.EntityClient;
...
EntityConnection conn = new EntityConnection(myContext.Connection.ConnectionString);
conn.Open();
EntityCommand cmd = conn.CreateCommand();
cmd.CommandText = @"Select t.MyValue From MyEntities.MyTable As t";
var queryExpression = cmd.Expression;
....
conn.Close();
Or something like that, check it out on MSDN.
And it's all on Ballmers tick :-)
There is also one on The Code Project, SQL Parser.
Good luck.
How parse SQL to Datatable or array in c#?
var str = "select 'a1,a2' f1, 2 f2;";
Regex.Matches(str, "(^|[\\s,\\,]){1}(\\'.*\\'\\s*\\w+|[^\\,^']*)[\\,,$,;]")
.Cast<Match>()
.Select(m => m.Value.Split(new[] { ' '}, StringSplitOptions.RemoveEmptyEntries)
.First().Replace("\'",""))
.ToArray();
How to parse AND/OR input in c#?
You will probably need to parse the input yourself, but with a parser generator such as ANTLR, it is not too much work.
Related Topics
Query to Convert from Datetime to Date MySQL
Sql Server 2008 - How to Convert Gmt(Utc) Datetime to Local Datetime
Weighted Average in T-Sql (Like Excel's Sumproduct)
Check If a Variable Is Null in Plsql
How to Increase Dbms_Output Buffer
How to Force MySQL to Perform Subquery First
How to Update All Columns of a Record Without Having to List Every Column
How to Get Column Names from a Query in SQL Server
Custom Sorting in SQL Order by Clause
How to Get the Employees with Their Managers
Pass Parameter in Table Valued Function Using Select Statement
How to Use MySQL Index Columns
Computed Column Cannot Be Persisted
Are There Reasons for Not Storing Boolean Values in SQL as Bit Data Types
Generating Seed Code from Existing Database in ASP.NET Mvc
How to Get Array/Bag of Elements from Hive Group by Operator