Microsoft KB Archive/67410

= INFO: Use User-Defined Data Type to Extract Current Time =

Article ID: 67410

Article Last Modified on 2/14/2005

-

APPLIES TO


 * Microsoft SQL Server 4.21a Standard Edition
 * Microsoft SQL Server 6.0 Standard Edition
 * Microsoft SQL Server 6.5 Standard Edition
 * Microsoft SQL Server 7.0 Standard Edition
 * Microsoft SQL Server 2000 Standard Edition

-



This article was previously published under Q67410



SUMMARY
You can create a user-defined data type that extracts the current time. The advantage of using user-defined data types is that you can bind rules and defaults to them for use in several different tables.



MORE INFORMATION
The following is an example of creating a data type with the functionality of extracting the current time by first creating a default, and then binding it to the user data type:

/* First, create the user type &quot;time&quot;. Please note that it is defined as not null. */

sp_addtype time, &quot;char(8)&quot;, &quot;not null&quot; go

/* Next, create the default &quot;timedft&quot;. This default uses the string function &quot;right&quot; to convert it to type char. */

create default timedft as right (getdate,8) go

/* Now, bind the result to the user data type. */

sp_bindefault timedft, time

/* Create the table with this user data type. */

create table test (curtime time, test int)

/* Since the data type was created as not null, any time a value is not supplied for the curtime column, the current time will be input into the column. */

insert test (test) values (1)

go

select * from test go

Curtime test --- -- 4:24 PM    1

Additional query words: Transact-SQL

Keywords: kbinfo kbusage KB67410

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.