cayenne icon indicating copy to clipboard operation
cayenne copied to clipboard

Case when statement implementation

Open Ivan-nikitko opened this issue 2 years ago • 0 comments

SQLBulder API example


   SelectBuilder builder = new SelectBuilder(column("OrderID"), column("Quantity"),
                caseWhen()
                        .when(column("Quantity").gt(value(30)).and(column("Quantity").lt(value(100))))
                        .then(value("The quantity from 30 to 100"))
                        .when(column("Quantity").eq(value(30)))
                        .then(value("The quantity is 30"))
                        .elseResult(value("The quantity is under 30"))
                        .as("QuantityText"))
                .from(table("OrderDetails"));

Expression API example

Expression caseWhenNoDefault = caseWhen(
                List.of((betweenExp("estimatedPrice", 0, 9)),
                        (betweenExp("estimatedPrice", 10, 20))),
                List.of((wrapScalarValue("firstThenResult")),
                        (wrapScalarValue("secondThenResult")))),
                wrapScalarValue("defaultResult"));

Ivan-nikitko avatar Aug 14 '23 12:08 Ivan-nikitko