ISqlHavingAndOr<TBuilder>.AndHavingValue(string left, object value) Method
.NET Standard 2.x
Adds the AND
logical operator and a search condition to the HAVING
clause. Specifies a SQL expression on the left the operator and a specific value on the right of the operator. The operator is '='.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
TBuilder AndHavingValue(string left, object value);
Parameters
left
System.String
An expression on the left of the operator.
value
System.Object
The specific value on the right of the operator.
Returns
TBuilder
Returns the TBuilder
object which can be used to add more search conditions to the current HAVING
clause.
Examples
The following code example demonstrates how to use the AndHavingValue method to add an AND condition to the HAVING clause.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlHavingAndOrExamples
{
public class AndHavingValueExample
{
private readonly SchoolContext _context;
public AndHavingValueExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example1()
{
var sqlQueryBuilder = new SqlQueryBuilder();
// Groups "StudentGrade" table by StudentID and CourseID, and gets the sum of Grade of each group.
// Specifies the HAVING condition for group as "StudentID > 0", and CourseID equal to 2030.
sqlQueryBuilder
.Select("StudentID")
.Select("sum(Grade)")
.From("StudentGrade")
.GroupBy("StudentID, CourseID")
.HavingRaw("StudentID > 0")
.AndHavingValue("CourseID", 2030)
.ToSqlString(_context);
// Converts to raw SQL for the database corresponding to the data context.
string sql = sqlQueryBuilder.ToSqlString(_context);
Console.WriteLine(sql);
/*This code example produces the following output:
SELECT
[StudentID],
sum(Grade)
FROM [StudentGrade]
GROUP BY
[StudentID],
[CourseID]
HAVING ([StudentID] > 0
AND [CourseID] = 2030)
*/
}
}
}
Applies to
.NET Standard
2.x