Class Case
Represents a SQL searched CASE expression with one or more WHEN/THEN branches and an optional ELSE.
Implements
Inherited Members
Namespace: SuperOffice.Data.SQL
Assembly: SoDataBase.dll
Syntax
public class Case : Argument, ICloneable
Remarks
Generates SQL of the form:
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
[ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result.
If no condition matches and no ELSE is provided, SQL returns NULL.
All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.
Parameters inside the CASE expression are always rendered as @Pn placeholders,
even when the CASE appears in a SELECT clause (where parameters would normally be
inlined). The Dialect temporarily switches to
SqlSection.Restriction mode while rendering the CASE to achieve this.
To construct a CASE expression, use the fluent builder via the factory:
S.FieldExpression.Case()
.When(condition1, result1)
.When(condition2, result2)
.Else(elseResult)
Constructors
Case()
Create an empty CASE expression. Add branches with When(Restriction, Argument) and optionally Else(Argument).
Declaration
public Case()
Remarks
At least one When(Restriction, Argument) branch must be added before the CASE can be rendered. The DataType is determined by the first WHEN branch added.
Properties
ElseArgument
The optional ELSE result. Null means SQL returns NULL when no condition matches.
Declaration
public Argument ElseArgument { get; }
Property Value
| Type | Description |
|---|---|
| Argument |
Remarks
Generates SQL of the form:
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
[ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result.
If no condition matches and no ELSE is provided, SQL returns NULL.
All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.
Parameters inside the CASE expression are always rendered as @Pn placeholders,
even when the CASE appears in a SELECT clause (where parameters would normally be
inlined). The Dialect temporarily switches to
SqlSection.Restriction mode while rendering the CASE to achieve this.
To construct a CASE expression, use the fluent builder via the factory:
S.FieldExpression.Case()
.When(condition1, result1)
.When(condition2, result2)
.Else(elseResult)
HasElse
True if an ELSE branch was provided.
Declaration
public bool HasElse { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Generates SQL of the form:
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
[ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result.
If no condition matches and no ELSE is provided, SQL returns NULL.
All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.
Parameters inside the CASE expression are always rendered as @Pn placeholders,
even when the CASE appears in a SELECT clause (where parameters would normally be
inlined). The Dialect temporarily switches to
SqlSection.Restriction mode while rendering the CASE to achieve this.
To construct a CASE expression, use the fluent builder via the factory:
S.FieldExpression.Case()
.When(condition1, result1)
.When(condition2, result2)
.Else(elseResult)
WhenClauses
The WHEN/THEN branches, evaluated in order.
Declaration
public IReadOnlyList<(Restriction Condition, Argument Result)> WhenClauses { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<(Restriction Condition, Argument Result)> |
Remarks
Generates SQL of the form:
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
[ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result.
If no condition matches and no ELSE is provided, SQL returns NULL.
All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.
Parameters inside the CASE expression are always rendered as @Pn placeholders,
even when the CASE appears in a SELECT clause (where parameters would normally be
inlined). The Dialect temporarily switches to
SqlSection.Restriction mode while rendering the CASE to achieve this.
To construct a CASE expression, use the fluent builder via the factory:
S.FieldExpression.Case()
.When(condition1, result1)
.When(condition2, result2)
.Else(elseResult)
Methods
Clone()
Deep-clone this CASE expression. All WHEN conditions, THEN results, and the ELSE result are cloned. Parameter values are shared between the original and the clone.
Declaration
public override object Clone()
Returns
| Type | Description |
|---|---|
| object |
Overrides
Remarks
Generates SQL of the form:
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
[ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result.
If no condition matches and no ELSE is provided, SQL returns NULL.
All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.
Parameters inside the CASE expression are always rendered as @Pn placeholders,
even when the CASE appears in a SELECT clause (where parameters would normally be
inlined). The Dialect temporarily switches to
SqlSection.Restriction mode while rendering the CASE to achieve this.
To construct a CASE expression, use the fluent builder via the factory:
S.FieldExpression.Case()
.When(condition1, result1)
.When(condition2, result2)
.Else(elseResult)
Else(Argument)
Set the ELSE branch, returned when no WHEN condition matches.
Declaration
public Case Else(Argument elseResult)
Parameters
| Type | Name | Description |
|---|---|---|
| Argument | elseResult | The ELSE result. Must have the same DataType as the THEN branches. |
Returns
| Type | Description |
|---|---|
| Case | This CASE expression, for fluent chaining. |
Remarks
Generates SQL of the form:
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
[ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result.
If no condition matches and no ELSE is provided, SQL returns NULL.
All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.
Parameters inside the CASE expression are always rendered as @Pn placeholders,
even when the CASE appears in a SELECT clause (where parameters would normally be
inlined). The Dialect temporarily switches to
SqlSection.Restriction mode while rendering the CASE to achieve this.
To construct a CASE expression, use the fluent builder via the factory:
S.FieldExpression.Case()
.When(condition1, result1)
.When(condition2, result2)
.Else(elseResult)
GetMainField()
Return the representative FieldInfo for this CASE expression. Returns the first non-null main field found by checking THEN results in order, then the ELSE result. Used by the query framework to determine table involvement.
Declaration
public override FieldInfo GetMainField()
Returns
| Type | Description |
|---|---|
| FieldInfo |
Overrides
Remarks
Generates SQL of the form:
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
[ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result.
If no condition matches and no ELSE is provided, SQL returns NULL.
All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.
Parameters inside the CASE expression are always rendered as @Pn placeholders,
even when the CASE appears in a SELECT clause (where parameters would normally be
inlined). The Dialect temporarily switches to
SqlSection.Restriction mode while rendering the CASE to achieve this.
To construct a CASE expression, use the fluent builder via the factory:
S.FieldExpression.Case()
.When(condition1, result1)
.When(condition2, result2)
.Else(elseResult)
When(Restriction, Argument)
Add a WHEN/THEN branch. Conditions are evaluated in the order they are added.
Declaration
public Case When(Restriction condition, Argument result)
Parameters
| Type | Name | Description |
|---|---|---|
| Restriction | condition | The WHEN condition. |
| Argument | result | The THEN result. Must have the same DataType as the first branch. |
Returns
| Type | Description |
|---|---|
| Case | This CASE expression, for fluent chaining. |
Remarks
Generates SQL of the form:
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
[ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result.
If no condition matches and no ELSE is provided, SQL returns NULL.
All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.
Parameters inside the CASE expression are always rendered as @Pn placeholders,
even when the CASE appears in a SELECT clause (where parameters would normally be
inlined). The Dialect temporarily switches to
SqlSection.Restriction mode while rendering the CASE to achieve this.
To construct a CASE expression, use the fluent builder via the factory:
S.FieldExpression.Case()
.When(condition1, result1)
.When(condition2, result2)
.Else(elseResult)