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 2000 Forums
 SQL Server Development (2000)
 datetime problem when importing data

Author  Topic 

donar
Starting Member

22 Posts

Posted - 2004-10-05 : 07:45:08
I am tring to import data from text file to SQL server 2000, the table contains two fields: start_date, end_date, both of them are smalldatetime. so if the text file look like this:
1999,2000
2002,2004

I will get an error when tring to import.

if i change the text file format to:
1999 01, 2000 01
2001 01, 2004 01
i will not have a problem importing them.

The problem is I do not want to do that, How can I import only year into the datetime field.


Thanks!

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2004-10-05 : 08:13:33
A datetime field in SQL Server cannot contain only the year, it must be a complete date. If necessary, you can default it to the first day of the year, something like:

CAST(CAST(yearfield AS varchar) + '0101' AS datetime)

OS
Go to Top of Page
   

- Advertisement -