Using Type Checking Functions

These functions check if an expression is of – or can be converted to – as specific data type.

ISBOOLEAN

Returns true if the specified expression can be converted to a Boolean; otherwise, it returns false. If the input expression is a string, possible conversion to Boolean will be checked using the invariant culture.

Examples:

SELECT isboolean(false) --returns true
SELECT isboolean(1) --returns true
SELECT isboolean('a') --returns false

ISBOOLEANCULTURE

Returns true if the specified expression can be converted to a Boolean; otherwise, it returns false. If the input expression is a string and the COLLATE keyword is not specified, the conversion is checked using the culture of the Data Model’s collation.

Examples:

SELECT isbooleanculture(false) --returns true
SELECT isbooleanculture(1) --returns true
SELECT isbooleanculture('1,1') --returns false in the en-us culture
SELECT isbooleanculture('1,1' COLLATE it-it_ci) --returns true

ISDATETIME

Returns true if the specified expression can be converted to a DateTime; otherwise, it returns false. If the input expression is a string, possible conversion to DateTime will be checked using the invariant culture.

Examples:

SELECT isdatetime(now()) --returns true
SELECT isdatetime(1) --returns true
SELECT isdatetime('09/29/2021') --returns true
SELECT isdatetime('29/09/2021') --returns false

ISDATETIMECULTURE

Returns true if the specified expression can be converted to a DateTime; otherwise, it returns false. If the input expression is a string and the COLLATE keyword is not specified, the conversion is checked using the culture of the Data Model’s collation.

Examples:

SELECT isdatetimeculture(now()) --returns true
SELECT isdatetimeculture(1) --returns true
SELECT isdatetimeculture('09/29/2021') --returns true
SELECT isdatetimeculture('29/09/2021') --returns false in the en-us culture
SELECT isdatetimeculture('29/09/2021' COLLATE it-it_ci) --returns true

ISNUMBER

Returns true if the specified expression can be converted to a Double; otherwise, it returns false. If the input expression is a string, possible conversion to Double will be checked using the invariant culture.

Examples:

SELECT isnumber(1) --returns true
SELECT isnumber(1.1) --returns true
SELECT isnumber(now()) --returns true
SELECT isnumber(CAST('00:10:00' AS TimeSpan)) --returns true
SELECT isnumber('1.1') --returns true
SELECT isnumber('1,1') --returns false

ISNUMBERCULTURE

Returns true if the specified expression can be converted to a Double; otherwise, it returns false. If the input expression is a string and the COLLATE keyword is not specified, the conversion is checked using the culture of the Data Model’s collation.

Examples:

SELECT isnumberculture(1) --returns true
SELECT isnumberculture(1.1) --returns true
SELECT isnumberculture(now()) --returns true
SELECT isnumberculture(CAST('00:10:00' AS TimeSpan)) --returns true
SELECT isnumberculture('1.1') --returns true in the en-us culture
SELECT isnumberculture('1,1') --returns false in the en-us culture
SELECT isnumberculture('1,1' COLLATE it-it_ci) --returns true

ISTIMESPAN

Returns true if the specified expression can be converted to a TimeSpan; otherwise, it returns false. If the input expression is a string, possible conversion to TimeSpan will be checked using the invariant culture.

Examples:

SELECT istimespan(gettimeofday(now())) --returns true
SELECT istimespan(1) --returns true
SELECT istimespan('00:01:10.123') --returns true
SELECT istimespan('00:01:10,123') --returns false

ISTIMESPANCULTURE

Returns true if the specified expression can be converted to a TimeSpan; otherwise, it returns false. If the input expression is a string and the COLLATE keyword is not specified, the conversion is checked using the culture of the Data Model’s collation.

Examples:

SELECT istimespanculture(gettimeofday(now())) --returns true
SELECT istimespanculture(1) --returns true
SELECT istimespanculture('00:01:10.123') --returns true in the en-us culture
SELECT istimespanculture('00:01:10,123') --returns false in the en-us culture
SELECT istimespanculture('00:01:10,123' COLLATE it-it_ci) --returns true