public string ToSQLWhere()
            {
                var clauses = new List <string>();

                if (MinExecs.GetValueOrDefault(0) > 0)
                {
                    clauses.Add("execution_count >= @MinExecs");
                }
                if (MinExecsPerMin.GetValueOrDefault(0) > 0)
                {
                    clauses.Add("(Case When DATEDIFF(mi, creation_time, qs.last_execution_time) > 0 Then CAST((1.00 * execution_count / DATEDIFF(mi, creation_time, qs.last_execution_time)) AS money) Else Null End) >= @MinExecsPerMin");
                }
                if (MinLastRunDate.HasValue)
                {
                    clauses.Add("qs.last_execution_time >= @MinLastRunDate");
                }
                if (Database.HasValue)
                {
                    clauses.Add("Cast(pa.value as Int) = @Database");
                }

                return(clauses.Any() ? "\n       And " + string.Join("\n       And ", clauses) : "");
            }
            public string ToSQLWhere()
            {
                var clauses = new List <string>();

                if (MinExecs.GetValueOrDefault(0) > 0)
                {
                    clauses.Add("execution_count >= @MinExecs");
                }
                if (MinExecsPerMin.GetValueOrDefault(0) > 0)
                {
                    clauses.Add("(Case When DATEDIFF(mi, creation_time, qs.last_execution_time) > 0 Then CAST((1.00 * execution_count / DATEDIFF(mi, creation_time, qs.last_execution_time)) AS money) Else Null End) >= @MinExecsPerMin");
                }
                if (Search.HasValue())
                {
                    clauses.Add("SUBSTRING(st.text, ( qs.statement_start_offset / 2 ) + 1, ( ( CASE qs.statement_end_offset WHEN -1 THEN DATALENGTH(st.text) ELSE qs.statement_end_offset END - qs.statement_start_offset ) / 2 ) + 1) Like '%' + @Search + '%'");
                }
                if (MinLastRunDate.HasValue)
                {
                    clauses.Add("qs.last_execution_time >= @MinLastRunDate");
                }

                return(clauses.Any() ? " WHERE " + string.Join("\n  AND ", clauses) : "");
            }