Hi, as I was comparing the table name extraction from the TSqlParser (which uses Microsoft.SqlServer.TransactSql.ScriptDom) with an extraction I once wrote (which uses Microsoft.SqlServer.Management.SqlParser). I realized one issue, where the TSqlParser is not returning the correct tables names.
Example (see query.txt attached):
- My parser recognized 15 distinct tables
- TSqlParser recognized 14 distinct tables. A nested query within a column was not successfully discovered (Table9 in the attachment)
| Expected result |
Actual result |
| #TempTable1 |
#TempTable1 |
| #TempTable2 |
#TempTable2 |
| #TempTable3 |
#TempTable3 |
| #TempTable4 |
#TempTable4 |
| #TempTable5 |
#TempTable5 |
| #TempTable6 |
#TempTable6 |
| Table1 |
Table1 |
| Table2 |
Table2 |
| Table3 |
Table3 |
| Table4 |
Table4 |
| Table5 |
Table5 |
| Table6 |
Table6 |
| Table7 |
Table7 |
| Table8 |
Table8 |
| Table9 |
- |
Sample code
SqlStatement sqlStatement = new SqlStatement();
if (sqlStatement.ParseString(mySqlQuery))
{
// Sorry, I am lazy so I aggregate the result and compare it in Excel
string tableNames = sqlStatement.getTableNames().OrderBy(p => p).Aggregate((i, j) => i + "\n" + j);
}
query.txt
(Edit: 14.11.2018, false query.txt was uploaded. Find attached the correct one)
Hi, as I was comparing the table name extraction from the TSqlParser (which uses Microsoft.SqlServer.TransactSql.ScriptDom) with an extraction I once wrote (which uses Microsoft.SqlServer.Management.SqlParser). I realized one issue, where the TSqlParser is not returning the correct tables names.
Example (see query.txt attached):
Sample code
query.txt
(Edit: 14.11.2018, false query.txt was uploaded. Find attached the correct one)