Page 101 - SQL
P. 101
If the string value can't be converted to a numeric, date, or time format, it will result in an error.
You'll then need to use CAST or CONVERT for the conversion.
SELECT PARSE('Monday, 13 August 2012' AS datetime2 USING 'en-US') AS 'Date in English'
Date in English
2012-08-13 00:00:00.0000000
Logical and Mathmetical Function
SQL has two logical functions – CHOOSE and IIF.
The CHOOSE function returns an item from a list of values, based on its position in the list. This
position is specified by the index.
In the syntax, the index parameter specifies the item and is a whole number, or integer. The val_1
… val_n parameter identifies the list of values.
SELECT CHOOSE(2, 'Human Resources', 'Sales', 'Admin', 'Marketing' ) AS Result;
Result
Sales
In this example, you use the CHOOSE function to return the second entry in a list of departments.
The IIF function returns one of two values, based on a particular condition. If the condition is true,
it will return true value. Otherwise it will return a false value.
In the syntax, the boolean_expression parameter specifies the Boolean expression. The
true_value parameter specifies the value that should be returned if the boolean_expression
evaluates to true and the false_value parameter specifies the value that should be returned if the
boolean_expression evaluates to false.
SELECT BusinessEntityID, SalesYTD,
IIF(SalesYTD > 200000, 'Bonus', 'No Bonus') AS 'Bonus?'
FROM Sales.SalesPerson
GO
BusinessEntityID SalesYTD Bonus?
274 559697.5639 Bonus
275 3763178.1787 Bonus
285 172524.4512 No Bonus
https://riptutorial.com/ 83

