Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Problem Importing Column

Author  Topic 

rcr69er
Constraint Violating Yak Guru

327 Posts

Posted - 2008-01-03 : 05:18:31
Hi

I have a column in a .txt file that I am trying to import.
The field shows the time of a transaction in the format of "12:20 AM"
Does anyone know a way of importing the field as a time field as opposed to a VARCHAR type? I have tried importing it as a datetime type, but this doesnt seem to work.

Thanks

mcrowley
Aged Yak Warrior

771 Posts

Posted - 2008-01-03 : 13:30:39
SQL Server 2005 has no concept of a "time" datatype. Time datatypes are added to SQL 2008 (Katmai), though.

Is there a date that the transaction is also tied to, or do you only have the time?
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-01-03 : 14:22:05
SQL Server can convert that to a datetime datatype with a default date of 1900-01-01:

select TIME_ONLY = convert(datetime,'12:20 AM')


Results:
TIME_ONLY
------------------------------------------------------
1900-01-01 00:20:00.000

(1 row(s) affected)



CODO ERGO SUM
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-01-03 : 14:27:56
Care to let us know how you are doing the "importing"

It's a little grey

Buy as MVJ states:


DECLARE @d datetime
SET @d = '12:20 AM'
SELECT @d



Works just fine

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -