Send feedback on this topic.
Teradata.Client.Provider
Interval Day To Hour Data Type
.NET Data Provider for Teradata > Developer's Guide > Data Types > Interval Data Types > Interval Day To Hour Data Type

Schema Collections

The Schema collections return metadata for the Advanced SQL Engine objects. The notable metadata columns for the Interval Day-to-Hour data type are:

Column Name Description

COLUMN_TYPE

or

DATA_TYPE

Set to INTERVAL DAY TO HOUR.
FORMAT Format assigned to the SQL Engine object.
PROVIDERDBTYPE It is set to TdType.IntervalDayToHour.
INTERVAL_PRECISION The maximum number of digits for the Day component.

Schema Table

The TdDataReader.SchemaTable returns result set metadata. The notable metadata columns for the Interval Day-to-Hour data type are:

Column Name Description
NumericPrecision The maximum number of digits for the Day component.
DataType System.Type object for the System.TimeSpan structure.
ProviderType Set to TdType.IntervalDayToHour.
Format Format assigned to the SQL Engine object.
ProviderSpecificDataType System.Type object for the TdIntervalDayToHour structure.

Configuring Parameters

The following example shows how to configure an Interval Day-to-Hour parameter using DbType type declaration and a Base Class Library (BCL) value. The TdParameter.Precision property reflects the maximum number of digits for the Day component and it must be equal to or less than the target SQL Engine object (i.e. Column, Expression, Stored Procedure Parameters and etc.) declaration. The range of values are from One to Four.

Note

The Data Provider will throw an exception if the Day component of the System.TimeSpan value is greater than 9,999 Days.

The Data Provider will throw an exception if the System.TimeSpan.Days property is greater than the maximum permissible value specified by TdParameter.Precision property.

Note

The Data Provider truncates the Minutes, Seconds and Milliseconds components of the System.TimeSpan vlaue.

C#
Copy Code
TdParameter deliveryInterval = new TdParameter();
deliveryInterval.ParameterName = "deliveryDaysAndHours";

deliveryInterval.DbType = DbType.Object;

// Maximum number of Day digits
deliveryInterval.Precision = 2;

// 9 Days and 12 Hours.
deliveryInterval.Value = new System.TimeSpan(9, 12, 0, 0);

The following example shows how to configure an Interval Day-to-Hour parameter using TdType type declaration and a Provider Specific value. It is recommend to always set TdParameter.Precision property, however the Data Provider will utilize TdIntervalDayToHour.Precision property value when the TdParameter.Precision property is set to zero. .NET Applications can retrieve metadata from the Schema Collections or the Schema Table and apply the metadata to the TdParameter object.

Note

The Data Provider will throw an exception if the Interval Value is greater than the maximum permissible value specified by the TdParameter.Precision property.

C#
Copy Code
TdParameter deliveryInterval = new TdParameter();
deliveryInterval.ParameterName = "deliveryDaysAndHours";

deliveryInterval.TdType = TdType.IntervalDayToHour;

// Maximum number of Day digits
deliveryInterval.Precision = 2;

// 9 Days and 12 Hours.
deliveryInterval.ProviderSpecificValue = new TdIntervalDayToHour(9, 12);

Specifying Interval Day To Hour as Literal

The syntax for the Interval Day Literal is INTERVALsign'dddd hh'DAY TO HOUR. Interval Day-to-Hour literals consist of the word Interval followed by optional negative sign, character string literal representation of the number of Days (up to 4 digits ranging from 0 to 9999) and Hours (2 digits ranging from 00 to 23) and the phrase Day To Hour.

Note

We recommend to always use Parameters in order to take advantage of the SQL Engine's Request Cache.

The following example shows 10 Days and 3 hours represented as Interval Day-to-Hour Literal in the Command Text.

C#
Copy Code
using (TdConnection cn = new TdConnection("data source=x;UserId=y;Password=z;"))
{
    cn.Open();
    TdCommand cmd = cn.CreateCommand();

    // Delivery exceeding 10 days.
    cmd.CommandText = "SELECT Id, orderDate from Order where (CURRENT_DATE - OrderTimestamp) > INTERVAL'10 03'DAY TO HOUR ";

    using (TdDataReader reader = cmd.ExecuteReader())
    {
        if (reader.HasRows)
        {
            while (reader.Read())
            {
                Console.WriteLine("Id={0}", reader.GetInt64(0).ToString());
            }
        }
    }
}

Retrieving Interval Day To Hour Data

The following methods and properties return the column or parameter value as a System.TimeSpan structure.

  1. TdDataReader.GetTimeSpan
  2. TdDataReader.GetValue
  3. TdDataReader.GetFieldValue<TimeSpan>
  4. TdParameter.Value
  5. TdParameter.GetValue<TimeSpan>

The following methods and properties return the column or parameter value as a TdIntervalDayToHour structure.

  1. TdDataReader.GetTdIntervalDayToHour
  2. TdDataReader.GetProviderSpecificValue
  3. TdDataReader.GetFieldValue<TdIntervalDayToHour>
  4. TdParameter.ProviderSpecificValue
  5. TdParameter.GetValue<TdIntervalDayToHour>
C#
Copy Code
using (TdConnection cn = new TdConnection("data source=DS1;UserId=Joe;Password=XY;"))
{
    cn.Open();

    TdCommand cmd = cn.CreateCommand();
    cmd.CommandText = "SELECT Id, orderDate, deliveryDaysAndHours from Order where deliveryDaysAndHours > ?";
    cmd.Parameters.Add("deliveryDays", TdType.IntervalDayToHour);
    cmd.Parameters[0].Precison = 2;
    cmd.Parameters[0].Value = new TimeSpan(10, 3, 0, 0);

    using (TdDataReader reader = cmd.ExecuteReader())
    {
        if (reader.HasRows)
        {
            while (reader.Read())
            {
                Console.WriteLine("[TimeSpan] Delivery Days and Hours = {0}", reader.GetValue(2).ToString());
                Console.WriteLine("[TdIntervalDayToHour] Delivery Days and Hours = {0}", reader.GetTdIntervalDayToHour(2).ToString());
            }
        }
    }
}

/* Output:
    [TimeSpan] Delivery Days = 11.03:00:00.0000000
    [TdIntervalDayToHour] Delivery Days = 11 03
*/

See Also

Data Type Mappings

Accessor Methods for Retrieving Data

Configuring Parameters and Parameter Data Types