IIFSTR
Updated 2023-11-10 16:27:27.003000
Syntax
SELECT [westclintech].[wct].[IIFSTR] (
<@Condition, bit,>
,<@TrueValue, nvarchar(max),>
,<@FalseValue, nvarchar(max),>)
Description
Use the scalar function IIFSTR to return one of two values, depending on the evaluation of an expression.
Arguments
@FalseValue
the value returned if @Condition is false. The @Falsevalue argument can be of data types that are implicitly convertible to nvarchar or ntext.
@TrueValue
the value returned if @Condition is true. The @Truevalue argument can be of data types that are implicitly convertible to nvarchar or ntext.
@Condition
the expression being evaluated. The @Condition argument can be an expression of types that are implicitly convertible to bit.
Return Type
nvarchar(max)
Examples
CREATE TABLE #i
(
[recno] [float] NOT NULL,
[numerator] [float] NOT NULL,
[denominator] [float] NOT NULL
);
INSERT INTO #i
VALUES
(1, 3, -1);
INSERT INTO #i
VALUES
(1, 3, 0);
INSERT INTO #i
VALUES
(1, 3, 1);
SELECT recno,
numerator,
denominator,
Numerator / wct.IIFSTR(denominator, denominator, .01)
from #i;
This produces the following result.
{
"columns": [
{
"field": "recno",
"headerClass": "ag-right-aligned-header",
"cellClass": "ag-right-aligned-cell"
},
{
"field": "numerator",
"headerClass": "ag-right-aligned-header",
"cellClass": "ag-right-aligned-cell"
},
{
"field": "denominator",
"headerClass": "ag-right-aligned-header",
"cellClass": "ag-right-aligned-cell"
},
{
"field": " ",
"headerClass": "ag-right-aligned-header",
"cellClass": "ag-right-aligned-cell"
}
],
"rows": [
{
"recno": "1",
"numerator": "3",
"denominator": "-1",
" ": "-3"
},
{
"recno": "1",
"numerator": "3",
"denominator": "0",
" ": "300"
},
{
"recno": "1",
"numerator": "3",
"denominator": "1",
" ": "3"
}
]
}