def build_sql_file(filename, meta_data_string, select_clause, from_clause,
    variable_declarations=None):
    """Build SQL file string from components and write to `filename`"""
    with open(filename, 'w') as fout:
        print('Writing meta-data to {filename}...'.format(filename=filename))
        fout.write(meta_data_string)
        if variable_declarations:
            print('Writing variable declarations to {filename}...'.format(
                filename=filename))
            fout.write(variable_declarations)
        print('Writing select clause to {filename}...'.format(filename=
            filename))
        fout.write(select_clause)
        print('Writing from clause to {filename}...'.format(filename=filename))
        fout.write(from_clause)
