Send feedback on this topic.
Teradata.Client.Provider
Period( Date ) Data Type
.NET Data Provider for Teradata > Developer's Guide > Data Types > Period Data Types > Period( Date ) Data Type

Schema Collections

The Schema collections return metadata for the Advanced SQL Engine objects. The notable metadata columns for the Period(Date) data type are:

Column Name Description

COLUMN_TYPE

or

DATA_TYPE

Set to PERIOD DATE.
FORMAT Format assigned to the SQL Engine object.
PROVIDERDBTYPE Set to TdType.PeriodDate.

Schema Table

The TdDataReader.SchemaTable returns result set metadata. The notable metadata columns for the Period(Date) data type are:

Column Name Description
ColumnSize The maximum length in Characters.
DataType System.Type object for the System.String structure.
ProviderType Set to TdType.PeriodDate.
Format Format assigned to the SQL Engine object.
ProviderSpecificDataType System.Type object for the TdPeriodDate structure.

Configuring Parameters

The following example shows how to configure a Period(Date) 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 Period(Date) data type when required. The "SQL Functions, Operators, Expressions and Predicates" manual documents all implicit and explicit Data Type conversions.

C#
Copy Code
TdParameter deliveryPeriod = new TdParameter();

deliveryPeriod.DbType = DbType.String;

deliveryPeriod.Value = "(2011-02-01, 2011-02-15)";

The following example shows how to configure a Period(Date) parameter using TdType type declaration and a Provider Specific value. .NET Applications can retrieve metadata from the Schema Collections or the Schema Table and apply the metadata to the TdParameter object.

Note

TdDate.MaxValue is equivalent to the SQL Engine reserved word UNTIL_CHANGED

C#
Copy Code
TdParameter deliveryPeriod = new TdParameter();

deliveryPeriod.TdType = TdType.PeriodDate;

deliveryPeriod.ProviderSpecificValue = new TdPeriodDate(new TdDate(2011, 2, 1), TdDate.MaxValue);

Specifying Period(Date) as Literal

The syntax for the Period(Date) Literal is one of the following two forms: 

  1. PERIOD'(YYYY-MM-DD, YYYY-MM-DD)'
  2. PERIOD'(YYYY-MM-DD, UNTIL_CHANGED)'
Note

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

The following example shows all policies enacted starting from January 1, 2011.

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

    cmd.CommandText = "INSERT INTO Policy (PolicyId, Validity) VALUES (1001, PERIOD'(2011-01-01, UNTIL_CHANGED)')";

    cmd.ExecuteNonQuery();
}

Retrieving Period(Date) 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 TdPeriodDate structure.

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

    TdCommand cmd = cn.CreateCommand();
    cmd.CommandText = "SELECT PolicyId, Validity from Policy where Validity > ?";
    cmd.Parameters.Add("Validity", TdType.PeriodDate);
    cmd.Parameters[0].Value = new TdPeriodDate(new TdDate(2011, 2, 1), TdDate.MaxValue );

    using (TdDataReader reader = cmd.ExecuteReader())
    {
        if (reader.HasRows)
        {
            while (reader.Read())
            {
                Console.WriteLine("[String] Policy Validity = {0}", reader.GetString(1));
                Console.WriteLine("[TdPeriodDate] Policy Validity = {0}", reader.GetTdPeriodDate(1).ToString());
            }
        }
    }
}

/* Output:
    [String] Policy Validity =  (2011-03-01, 9999-12-31)
    [TdPeriodDate] Policy Validity =  (2011-03-01, 9999-12-31) 
*/

See Also

Data Type Mappings

Accessor Methods for Retrieving Data

Configuring Parameters and Parameter Data Types