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

Schema Collections

The Schema collections return metadata for the Advanced SQL Engine objects. The notable metadata columns for the Interval Month data type are:

Column Name Description

COLUMN_TYPE

or

DATA_TYPE

Set to INTERVAL MONTH.
FORMAT Format assigned to the SQL Engine object.
PROVIDERDBTYPE It is set to TdType.IntervalMonth.
INTERVAL_PRECISION The maximum number of digits for the Month component.

Schema Table

The TdDataReader.SchemaTable returns result set metadata. The notable metadata columns for the Interval Month data type are:

Column Name Description
NumericPrecision The maximum number of digits for the Month component.
DataType System.Type object for the System.String class.
ProviderType Set to TdType.IntervalMonth.
Format Format assigned to the SQL Engine object.
ProviderSpecificDataType System.Type object for the TdIntervalMonth structure.

Configuring Parameters

The following example shows how to configure an Interval Month parameter using DbType type declaration and a Base Class Library (BCL) value.

Note

The Data Provider sends a VarChar data type to the SQL Engine when TdParameter.DbType is set to DbType.String. The SQL Engine will perform an implicit conversion to the Interval Month data type when required. The "SQL Functions, Operators, Expressions and Predicates" manual documents all implicit and explicit Data Type conversions. 

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

deliveryInterval.DbType = DbType.String;

// DBS will perform implicit conversion.
deliveryInterval.Value = " 9";

The following example shows how to configure an Interval Month parameter using TdType type declaration and a Provider Specific value. The TdParameter.Precision property reflects the maximum number of digits for the Year 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. It is recommend to always set TdParameter.Precision property, however the Data Provider will utilize TdIntervalMonth.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 = "deliveryMonths";

deliveryInterval.TdType = TdType.IntervalMonth;

// Maximum number of digits for the Month component
deliveryInterval.Precision = 2;

deliveryInterval.ProviderSpecificValue = new TdIntervalMonth(9);

Specifying Interval Month as Literal

The syntax for the Interval Month Literal is INTERVALsign'dddd'MONTH. Interval Month literals consist of the word Interval followed by optional negative sign, character string literal representation of the number of months (up to 4 digits) and the word Month.

Note

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

The following example shows 10 Months represented as Interval Month 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 months.
    cmd.CommandText = "SELECT Id, orderDate from Order where ((CURRENT_DATE - OrderDate) MONTH) > INTERVAL'10'MONTH ";

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

Retrieving Interval Month Data

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

  1. TdDataReader.GetString
  2. TdDataReader.GetValue
  3. TdDataReader.GetFieldValue<String>
  4. TdParameter.Value
  5. TdParameter.GetValue<String>

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

  1. TdDataReader.GetTdIntervalMonth
  2. TdDataReader.GetProviderSpecificValue
  3. TdDataReader.GetFieldValue<TdIntervalMonth>
  4. TdParameter.ProviderSpecificValue
  5. TdParameter.GetValue<TdIntervalMonth>

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, deliveryMonths from Order where deliveryMonths > ?";
    cmd.Parameters.Add("deliveryMonthss", TdType.IntervalMonth);
    cmd.Parameters[0].Precison = 2;
    cmd.Parameters[0].Value = new TdIntervalMonth(2);

    using (TdDataReader reader = cmd.ExecuteReader())
    {
        if (reader.HasRows)
        {
            while (reader.Read())
            {
                Console.WriteLine("[String] Delivery Months = {0}", reader.GetString(2));
                Console.WriteLine("[TdIntervalMonth] Delivery Months = {0}", reader.GetTdIntervalMonth(2).ToString());
            }
        }
    }
}

/* Output:
    [String] Delivery Months =  3
    [TdIntervalMonth] Delivery Months =  3
*/

See Also

Data Type Mappings

Accessor Methods for Retrieving Data

Configuring Parameters and Parameter Data Types