DateTimePartExpression
The DateTimePartExpression is part of the Dynamic Where feature; it represents a call to the SQL function that extracts a part of given date like year, month etc.
Date parts that can be extracted:
Year |
Month |
Week |
Day |
Hour |
Minute |
Second |
Implementations
- DateTimePartExpression (.NET)
- DateTimePartExpression (Java)
- TDADateTimePartExpression (Delphi)
- DateTimePartExpression (JavaScript)
Example
Target SQL where
clause:
WHERE DATEPART(order_date, YEAR) = 2020
WhereExpression whereExpression = new BinaryExpression(
new DateTimePartExpression(
new FieldExpression("ORDERS", "order_date"),
DatePart.Year),
new ConstantExpression(2020, DataType.Integer),
BinaryOperator.Equal);
let whereExpression = BinaryExpression(
DateTimePartExpression(
FieldExpression("ORDERS", "order_date"),
DatePart.Year),
ConstantExpression(2020, DataType.Integer),
BinaryOperator.Equal)
WhereExpression where = new BinaryExpression(
new DateTimePartExpression(
new FieldExpression("ORDERS", "order_date"),
DatePart.Year),
new ConstantExpression(2020, DataType.Integer),
BinaryOperator.Equal);
let whereExpression = BinaryExpression(
DateTimePartExpression(
FieldExpression("ORDERS", "order_date"),
DatePart.Year),
ConstantExpression(2020, DataType.Integer),
BinaryOperator.Equal)
with ClientDataModule.tbl_ORDERS, DynamicWhere do begin
Expression := NewBinaryExpression(
NewDateTimePart(
NewField(LogicalName, 'order_date'),
ddpYear),
NewConstant(2020, datInteger),
dboEqual);
end;
myTable.dynamicWhere = new RemObjects.DataAbstract.DynamicWhere(
new RemObjects.DataAbstract.DateTimePartExpression(
new RemObjects.DataAbstract.FieldExpression("order_date"),
"Year"),
new RemObjects.DataAbstract.ConstantExpression("Integer", 2020),
"Equal");
Generated XML/JSON
<?xml version="1.0"?>
<query xmlns="http://www.remobjects.com/schemas/dataabstract/queries/5.0" version="5.0">
<where>
<binaryoperation operator="Equal">
<datetimepart part="Year">
<field tablename="ORDERS">order_date</field>
</datetimepart>
<constant type="Integer" null="0">2020</constant>
</binaryoperation>
</where>
</query>
{
"type": "query.where",
"expression": {
"type": "binaryoperation",
"left": {
"type": "datetimepart",
"part": "Year",
"expression": {
"type": "field",
"field": "order_date",
"table": "ORDERS"
}
},
"operator": "Equal",
"right": {
"type": "constant",
"datatype": "Integer",
"value": "2020"
}
}
}