Separate the SQL Commands in a SQL script
Sometimes you just want to get separate SQL statement from a big SQL script, this is not that easy in a SQL Server script, because there is no delimiter operator such as ; required to separate SQL statements in SQL Server script like Oracle or other databases do.
General SQL Parser can help you to achieve this quickly.
Code in Java:
TGSqlParser sqlparser = new TGSqlParser(EDbVendor.dbvmssql); sqlparser.sqlfilename = args[0]; int ret = sqlparser.getrawsqlstatements(); if (ret == 0){ for(int i=0;i<sqlparser.sqlstatements.size();i++){ System.out.println(sqlparser.sqlstatements.get(i).sqlstatementtype.toString()); System.out.println(sqlparser.sqlstatements.get(i).toString()); System.out.println(); } }else{ System.out.println(sqlparser.getErrormessage()); }
Download this dem: Java version