Share via


CAST Function

Topic Last Modified: 2009-07-22

Use the Structured Query Language (SQL) CAST Function to attribute a data type to a property in the returned recordset. Casting only supports Property Data Types.

Casting is optional and is primarily used for working with custom properties whose data type is not known by the Exchange store. The Exchange store recognizes all data types for the schema as installed by Microsoft® Exchange Server 2007 . Custom properties not cast are evaluated as string values. Casting Boolean properties is unnecessary.

CAST(value AS datatype)

The value is either a property or a literal string.

The datatype is an XML data type. XML data types are case-sensitive.

Remarks

By using base-64 encoding, you can encode binary custom property values in a format that can be sent in XML. All Exchange 2007 binary properties are base-64 encoded by default. The following clause is an example where "a98k231KJg823kj" is a base-64 encoded string.

WHERE CAST("custom:mybinaryprop" AS "bin.base64") > "a98k231KJg823kj"

If you want to encode using bin.hex, casting must be repeated on the comparison value as shown in these examples:

WHERE CAST("custom:mybinaryprop" AS "bin.hex") = CAST("08AF183B82" as "bin.hex")
WHERE CAST("custom:myprop" AS "string") = CAST("08AF183B82" as "bin.hex")

Examples

WHERE CAST("custom:mydateprop" AS "dateTime") > "1998-02-01T10:00"
WHERE "custom:count" > CAST("0" AS "int")
WHERE "custom:creationdate" = CAST("1999-10-22T22:12:40.296Z" as "dateTime.tz")
WHERE "custom:price" > CAST("34.88" AS "fixed.14.4")

You can cast universally unique identifier (UUID) properties with or without the braces:

WHERE CAST("myguid" as "uuid") = "F04DA480-65B9-11d1-A29F-00AA00C14882"
WHERE CAST("myguid" as "uuid") = "{F04DA480-65B9-11d1-A29F-00AA00C14882}"