Conditional Expression in SQL Server XQuery
By : Kasim Wirama, MCDBA, MCITP
XQuery has conditional construction like any other programming languages (C#, VB, etc). Let’s read through remaining of this article and see how XQuery conditional expression couldn’t be compared to programming languages.
Conditional construction for XQuery is :
If (conditional expression)
THEN then statement
ELSE else statement
Conditional expression has several output possibility:
1. It results empty sequence, so IF section evaluates it to FALSE, so “else statement” will be executed.
2. It results xs:Boolean value.
3. It results nodes sequence so it is evaluated as TRUE
If none of them, it will raise static error message.
Conditional construction in XQuery doesn’t call to other function whereas any programming languages (like C#, VB.NET) do. XQuery’s is comparable to CASE…WHEN…THEN…ELSE…END. And one more thing is that ELSE section is mandatory.
Simple thing yields business added-value.