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
 Transact-SQL (2005)
 Import test into datetime field

Author  Topic 

omega1983
Starting Member

40 Posts

Posted - 2009-12-11 : 12:33:40
I have a datetime field as follows:
birthdate (datetime,null)
sample: 1947-01-10 00:00:00.000

I have three separate text fields that can be brought together to make up a text version of a date
birthmonth char(2) birthday char(2) birthyear char(4)
sample: '1947','01','10'

I want to populate the birthdate (datetime,null)with the three text fields where the birthdate (datetime,null) is null. I tried this:
select birthmonth,birthday,birthyear
from birthday_table

update birthday_table
set birthdate = birthyear+'-'+birthmonth+'-'+birthday+'00:'+
+'00:'++'00:'++'0000'
where birthdate = '' or birthdate is null
and got the error message
Conversion failed when converting datetime from character string.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-12-11 : 12:36:07
i think this is enough

update birthday_table
set birthdate = birthyear+'-'+birthmonth+'-'+birthday
where birthdate = '' or birthdate is null


also are birthmonth etc nullable fields?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-12 : 01:39:54
or

update birthday_table
set birthdate = birthyear+birthmonth+birthday
where birthdate = '' or birthdate is null


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -