@Override
    public void serialize(QueryMetadata metadata, boolean forCountRow, SQLSerializer context) {
        if (!forCountRow && metadata.getModifiers().isRestricting() && metadata.getOrderBy().isEmpty()
                && !metadata.getJoins().isEmpty()) {
            metadata = metadata.clone();
            QueryModifiers mod = metadata.getModifiers();
            // use top if order by is empty
            if (mod.getOffset() == null) {
                // select top ...
                metadata.addFlag(new QueryFlag(QueryFlag.Position.AFTER_SELECT,
                        Expressions.template(Integer.class, topTemplate, mod.getLimit())));
            } else {
                // order by first column
                metadata.addOrderBy(Expressions.ONE.asc());
            }
        }
        context.serializeForQuery(metadata, forCountRow);

        if (!metadata.getFlags().isEmpty()) {
            context.serialize(Position.END, metadata.getFlags());
        }
    }
{@code SQLServer2012Templates} is an SQL dialect for Microsoft SQL Server 2012 and later

@author tiwe
querydsl-sql/src/main/java/com/querydsl/sql/SQLServer2012Templates.java