Storing dates as strings can be confusing because dates are meaningless without understanding what calendar system is being used.
The CADatetime sample defines two user-defined data types (CADatetime and CADate) which provide calendar-aware handling of dates and times.
Install directory:
drive:\Program Files\Microsoft SQL Server\90\Samples\Engine\Programmability\
CLR\CADateTime\
Scenario
Jane is a developer for Adventure Works Cycles. She has to write software that processes dates and times from around the world. She uses the CADatetime and CADate UDTs to help express dates in a particular calendar system.
Languages
Transact-SQL, Visual C# and Visual Basic.
Features
The CADatetime sample uses the following features of .
| Application Area | Features |
|---|---|
|
UDT Implementation |
CLR |
|
World-ready |
Satellite assemblies |
Prerequisites
Before running this sample, make sure the following software is installed:
-
or (SQL Server Express). You can obtain SQL Server Express free of charge from the SQL Server 2005 Express Edition Documentation and Samples
Web site
-
The AdventureWorks database, which is included with SQL Server 2005, and is also available at the SQL Server 2005 Express Edition Documentation and Samples
Web site .
-
The SQL Server 2005 Database Engine samples. These samples are included with SQL Server 2005 and are also included with the Microsoft Microsoft .NET Framework version 2.0 SDK 2.0.
-
.NET Framework SDK 2.0 or Microsoft Visual Studio 2005. You can obtain .NET Framework SDK free of charge. See Installing the .NET Framework SDK.
Building the Sample
To build the CADatetime sample
-
CD to the install directory and execute the following at a .NET Framework or Microsoft Visual Studio 2005 command prompt:
sn -k keypair.snk -
Build the resource files for the sample by executing the following commands in either an SDK command prompt window or a Visual Studio command prompt window:
cd CS\CADateTime\resourcesbuild.cmdcd ..\..\.. -
Compile the sample by using Visual Studio 2005 and the provided Visual Studio solution or using , which is included in the .NET Framework SDK 2.0, by executing a command similar to the following at a command prompt:
msbuild /nologo /verbosity:quiet /property:Configuration=Debug CS\ CADateTime.sln -
Make sure the AdventureWorks database is installed.
-
If you did not install the SQL Server engine samples in the default location, modify the path in the CREATE ASSEMBLY part of the script in Scripts\InstallCS.sql and Scripts\InstallVB.sql to refer to the location where the samples were installed.
-
If you are not an administrator for the SQL Server instance you are using, you must have an administrator grant you CreateAssembly permission in order to complete the installation.
-
Open the scripts\installCS.sql or scripts\installVB.sql file (depending on whether you compiled the Visual C# project or the Visual Basic project) in and execute the script contained in the file, or execute a command similar to the following in a command prompt window:
sqlcmd -E -I -i Scripts\InstallCS.sql
Running the Sample
To run the CADatetime sample
-
Open the scripts\test.sql file in SQL Server Management Studio and execute the script contained in the file, or execute the following command in a command prompt window:
sqlcmd -E -I -i Scripts\test.sql
Removing the Sample
To remove the CADatetime sample
-
Open the scripts\cleanup.sql file in SQL Server Management Studio and execute the script contained in the file, or execute the following command in a command prompt window:
sqlcmd -E -I -i Scripts\cleanup.sql
Comments
The CLR for SQL Server 2005 or SQL Server Express must be enabled for this sample to work correctly.
Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples. Sample applications and assemblies should not be connected to or used with your production SQL Server database or your report server without the permission of the system administrator.