Some notes on software development... RSS 2.0
# Wednesday, 20 August 2008

The following function returns the number of SQL Server statements from a SQL text file using GO as the batch separator:

private int GetBatchCount(string scriptFile)
{
    string allSql = string.Empty;

    using (StreamReader sr = new StreamReader(scriptFile)) 
    {
        allSql = sr.ReadToEnd();
        sr.Close();
    }
    
    Regex regex = new Regex(@"^\s*GO\s*$", RegexOptions.IgnoreCase | RegexOptions.Multiline);

    return regex.Split(allSql).Length - 1;    
}
Wednesday, 20 August 2008 12:32:22 (GMT Standard Time, UTC+00:00)  #    -
C#
Navigation

Sign In
Extras
Statistics
Total Posts: 116
This Year: 0
This Month: 0
This Week: 0
Comments: 36
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2018
Hadrian Phillips

All Content © 2018, Hadrian Phillips
DasBlog theme 'Business' created by Christoph De Baene (delarou)