Obviously you do Need some SQL parsing. This solution is maybe overkill, on the other hand it will help you in case you go in future for more complex SQL statements.
With
TSql110Parser
you can easely let parse an SQL. You need to add the reference for
Microsoft.SqlServer.TransactSql.ScriptDom
, see also link at the end of this answer.
private void buttonParseSQL_Click(object sender, EventArgs e)
{
string sql = "SELECT a, b, c FROM tbl";
IList<parseerror> errors;
TSql110Parser parser = new TSql110Parser(true);
var sqlFragment = parser.Parse(new System.IO.StringReader(sql), out errors);
IList<tsqlparsertoken> tokenStream= sqlFragment.ScriptTokenStream;
foreach (TSqlParserToken token in tokenStream)
{
}
}
Here you will find some usefull innformation:
Removing Comments from SQL | Michael J. Swart[
^]Hope it helps.