Send feedback on this topic.
Teradata.Client.Provider
TdIntervalYearToMonth Structure
Members  Example 



Teradata.Client.Provider Namespace : TdIntervalYearToMonth Structure
TdIntervalYearToMonth represents an interval of time defining a duration in years and/or months. The year precision is configurable from 1 - 4 significant digits.
Object Model
TdIntervalYearToMonth StructureTdIntervalYearToMonth StructureTdIntervalYearToMonth StructureTdIntervalYearToMonth StructureTdIntervalYearToMonth StructureTdIntervalYearToMonth Structure
Syntax
Remarks

TdIntervalYearToMonth is a .NET Data Provider for Teradata specific type, designed to support a SQL Interval Year To Month data type.

The TdIntervalYearToMonth supports the Teradata Interval Year (precision) To Month data type where precision indicates the number of digits in the years (from 1 - 4).

The interval value must be specified in the following format :

[sign][years]-[mm]

Below is the description of each format item.

Format Element Description
sign Optional - or space character.
years Required number of years (one to four digits in length).
mm Required 2 digits representing the months from 00 - 11.

.NET does not have a system type that directly corresponds to the SQL Interval Year To Month data type. The .NET Data Provider for Teradata Version 13.0 version and prior versions map Interval Year To Month to System.String. With version 13.1 of the provider, TdIntervalYearToMonth is available to retrieve and manipulate data of type Interval Year To Month.

The range of values for each TdInterval precision is as follows:

Type and Precision Minimum Maximum
TdIntervalYearToMonth(1) -'9-11' '9-11'
TdIntervalYearToMonth(2) -'99-11' '99-11'
TdIntervalYearToMonth(3) -'999-11' '999-11'
TdIntervalYearToMonth(4) -'9999-11' '9999-11'

TdIntervalYearToMonth also supports TdIntervalYearToMonth.Null. This is a very important feature. An application is no longer required to call TdDataReader.IsDBNull before invoking the corresponding TdDataReader "Get" method. This will improve overall performance.

A TdIntervalYearToMonth structure allows arithmetic, comparision and conversion operations to be performed.

A TdIntervalYearToMonth may also be specified as an in, out, or in/out parameter to a stored procedure. In order to maintain backward compatibility with previous versions of the provider (release 13.0 and prior), a Connection String Attribute TdConnectionStringBuilder.EnableTdIntervals has been added. When the EnableTdIntervals attribute is true, TdParameter.ProviderSpecificValue will return the data as the provider specific type of TdIntervalYearToMonth. When EnableTdIntervals is false, TdParameter.ProviderSpecificValue will return the data as a .NET Framework Library data type of String.

The TdParameter.Value will return the .NET Framework Library data type of System.String whether EnableTdIntervals is true or false.

For more information on the Teradata Interval Year To Month data type please see the 'SQL Data Types and Literals' manual.

Example

The following example shows how to retrieve a TdIntervalYearToMonth, modify the interval, and then update the table.

Public void IntervalExample(TdCommand cmd, String model)
{
   cmd.Parameters.Clear();
   
   cmd.CommandText = "SELECT StartDate, LeaseLen FROM AutoLeases " +
                     "WHERE Model = ?";
             
   cmd.CommandType = CommandType.Text;
             
   cmd.Parameters.Add(null, TdType.VarChar, 10,
        ParameterDirection.Input, true, 0, 0, null,    
        DataRowVersion.Default, model);
             
  Int32 row = 0;
  TdDate [] startDate;
  TdIntervalYearToMonth [] leaseLen;
             
  using (TdDataReader dr = cmd.ExecuteReader())
  { 
      startDate = new TdDate[dr.RecordsReturned];
      leaseLen = new TdIntervalYearToMonth [dr.RecordsReturned];
             
      // Specifying an interval of 2 years 1 month with a precision of 2
      TdIntervalYearToMonth extraTime = new TdIntervalYear(2, 1, 2);
   
      while (dr.Read())
      {
         // Retrieving the dates
        startDate[row] = dr.GetTdDate(0);
        leaseLen[row] = dr.GetTdIntervalYearToMonth(1);
             
         // Adding the extra time to the StartDate
         startDate[row] = startDate[row] + extraTime;
             
         // Adding the extra time to the lease length;
         leaseLen[row] = leaseLen[row] + extraTime;
             
         row++;
      } 
   }
            
   cmd.Parameters.Clear();
             
   cmd.CommandText = "UPDATE AutoLeases " +
                     "SET StartDate = ?, LeaseLen = ? " +
                     "WHERE Model = ?";
             
   cmd.Parameters.Add(null, TdType.Date, 0,
         ParameterDirection.Input, true, 0, 0, null,    
         DataRowVersion.Default, null);
             
   cmd.Parameters.Add(null, TdType.IntervalYearToMonth, 0,
         ParameterDirection.Input, true, 0, 0, null,    
         DataRowVersion.Default, null);
             
   cmd.Parameters.Add(null, TdType.VarChar, 9,
         ParameterDirection.Input, true, 0, 0, null,    
         DataRowVersion.Default, model);
             
   row--;
   while(row >= 0)
   {
      cmd.Parameters[0].Value = startDate[row];
      cmd.Parameters[1].Value = leaseLen[row];
             
      cmd.ExecuteNonQuery();
      row--;
   }
}
Inheritance Hierarchy

System.Object
   System.ValueType
      Teradata.Client.Provider.TdIntervalYearToMonth

Requirements

Target Platforms: Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019

See Also

Reference

TdIntervalYearToMonth Members
Teradata.Client.Provider Namespace
EnableTdIntervals Property
Interval Connection String Attribute
Enabling Provider Specific Types
Provider Specific Type: Interval Type Overview