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

Schema Collections

The Schema collections return metadata for the Teradata Database objects. The notable metadata columns for the Interval Year data type are:

Column Name Description

COLUMN_TYPE

or

DATA_TYPE

Set to INTERVAL YEAR.
FORMAT Teradata Database Format assigned to the Teradata Database object.
PROVIDERDBTYPE Set to TdType.IntervalYear.
INTERVAL_PRECISION The maximum number of digits for the Year component.

Schema Table

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

Column Name Description
NumericPrecision The maximum number of digits for the Year component.
DataType System.Type object for the System.String structure.
ProviderType Set to TdType.IntervalYear.
Format Teradata Database Format assigned to the Teradata Database object.
ProviderSpecificDataType System.Type object for the TdIntervalYear structure.

Configuring Parameters

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

Note

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

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

deliveryInterval.DbType = DbType.String;

deliveryInterval.Value = " 1";

The following example shows how to configure an Interval Year 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 Teradata Database 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 TdIntervalYear.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 = "deliveryYears";

deliveryInterval.TdType = TdType.IntervalYear;

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

deliveryInterval.ProviderSpecificValue = new TdIntervalYear(1);

Specifying Interval Year as Literal

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

Note

We recommend to always use Parameters in order to take advantage of the Teradata Database Request Cache.

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

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

Retrieving Interval Year 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 TdIntervalYear structure.

  1. TdDataReader.GetTdIntervalYear
  2. TdDataReader.GetProviderSpecificValue
  3. TdDataReader.GetFieldValue<TdIntervalYear>
  4. TdParameter.ProviderSpecificValue
  5. TdParameter.GetValue<TdIntervalYear>

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, deliveryYears from Order where deliveryYears > ?";
    cmd.Parameters.Add("deliveryYears", TdType.IntervalYear);
    cmd.Parameters[0].Precison = 2;
    cmd.Parameters[0].Value = new TdIntervalYear(1);

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

/* Output:
    [String] Delivery Years =  1
    [TdIntervalYear] Delivery Years =  1
*/

See Also

Data Type Mappings

Accessor Methods for Retrieving Data

Configuring Parameters and Parameter Data Types