diff --git a/SQL/Schema/CrossDB.cs b/SQL/Schema/CrossDB.cs index 99ad24f5..b6690ea8 100644 --- a/SQL/Schema/CrossDB.cs +++ b/SQL/Schema/CrossDB.cs @@ -263,7 +263,7 @@ public static bool Add(string name, string type, string conn) private static string GetFirstTableNameFromSql(string sql) { //获取原始表名 - string[] items = sql.Replace("\r\n", " ").Split(' '); + string[] items = sql.Replace("\r\n", " ").Replace("\t", " ").Split(' '); if (items.Length == 1) { return sql; }//单表名 if (items.Length > 3) // 总是包含空格的select * from xxx { @@ -282,17 +282,26 @@ private static string GetFirstTableNameFromSql(string sql) { startFrom = false; } - else if (item.IndexOf('.') > -1) + else { - if (item.ToLower().StartsWith("dbo.")) + string tableName = item; + if (item.IndexOf(')') > -1) { - return item.Substring(4); + tableName = item.Substring(0, item.IndexOf(')')); + } + + if (tableName.IndexOf('.') > -1) + { + if (tableName.ToLower().StartsWith("dbo.")) + { + return tableName.Substring(4); + } + startFrom = false; + } + else + { + return tableName; } - startFrom = false; - } - else - { - return item; } } }