Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

PI SQL Data Access Server (RTQP Engine)

Conversion functions

  • Last UpdatedDec 19, 2022
  • 2 minute read

The RTQP Engine supports conversion functions, which change an expression from one data type to another. These functions are similar to the CAST expression, but some have additional arguments that expand the conversion functionality.

The function name is the resulting data type. For example, if you want to convert data to string data type, you would use STRING(x).

If you can change the data type using CAST, you can use the corresponding conversion function. Most of conversion functions use a single argument and are straightforward in their use. Those functions are not documented further. Functions that require multiple arguments or additional explanation are documented here.

DOUBLE with TimeSpan

Use the DOUBLE function to convert a TimeSpan (x) to a floating-point number that represents the number of date/time units (timeUnit). The following are valid values for the TimeUnit enumeration: day, hour, minute, second, millisecond, microsecond, or nanosecond.

DOUBLE(x TimeSpan, y TimeUnit)

For example, DOUBLE('7d', hour) returns 168 and DOUBLE('7d', minute) returns 10080.

TIMESPAN with Double

Use the TIMESPAN function to convert a double (x) to a TimeSpan using the specified date/time units (timeUnit). The following are valid values for the TimeUnit enumeration: day, hour, minute, second, millisecond, microsecond, or nanosecond.

TIMESPAN(x Double, y TimeUnit)

For example, TIMESPAN(8970.25, minute) returns 6.05:30:15 and TIMESPAN(8970.25, hour) returns 373.18:15:00.

INT64 with TimeSpan

Use the INT64 function to convert a TimeSpan (timeSpan) to an integer that represents the number of ticks. A tick equals 100 nanoseconds or one ten-millionth of a second. To ensure the function interprets the value as a TimeSpan, wrap the value in the TimeSpan function.

INT64(TimeSpan(timeSpan TimeSpan))

For example, INT64(TimeSpan(N'1m')) returns 600000000.

TIMESPAN with Int64

Use the TIMESPAN function to convert an Int64 (n) that represents the number of ticks to a TimeSpan. A tick equals 100 nanoseconds or one ten-millionth of a second.

TIMESPAN(n Int64)

For example, TIMESPAN(111222333444555) returns 128.17:30:33.3444555.

TIMESPAN with String

Use the TIMESPAN function to convert a String (s) to a TimeSpan.

TIMESPAN(s String)

The following formats for the String are supported:

{+|-}<number>[.<number>] <interval> { [+|-]<number>[.<number>] <interval> }*

or

{+|-}{ hh | [hh][:[mm][:ss[.ff]]] }

or

[-]d.hh:mm[:ss[.ff]]

For full details about the first two formats, see the Remarks section of the AF SDK Reference page AFTimeSpan.Parse Method (String, IFormatProvider).

For example, TIMESPAN('10 hours 15 minutes') returns 10:15:00.

TIMEPERIOD with String

Use the TIMEPERIOD function to convert a String (s) to a TimePeriod.

TIMEPERIOD(s String)

The following formats for the String are supported:

<number>[.<number>] <interval> { <number>[.<number>] <interval> }*

or

{ hh | [hh][:[mm][:ss[.ff]]] }

or

d.hh:mm[:ss[.ff]]

For full details about the first two formats, see the Remarks section of the AF SDK Reference page AFTimeSpan.Parse Method (String, IFormatProvider).

For example, TIMEPERIOD('10 hours 15 minutes') returns 10:15:00.

In This Topic
TitleResults for “How to create a CRG?”Also Available in