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
 Transact-SQL (2000)
 inserting dates

Author  Topic 

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-16 : 12:11:11
ok this is a really stupid question and it hurt even to ask, but anyway...

create table MyTable
(
col1 varchar(15),
col2 smalldatetime,
col3 int
)

insert into myTable (col1, col2, col3)
select '1234', '18.3.2002', 2 union all
select '12345', '18.5.2002', 3 union all
select '12341', '13.3.2004', 2 union all
select '12343', '4.8.2006', 1

in the insert int says:
Server: Msg 296, Level 16, State 3, Line 28
The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.
The statement has been terminated.

why, oh why?? and how to fix it?

and to think i used to know this stuff... maybe it's time to go home :))

Go with the flow & have fun! Else fight the flow :)

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-08-16 : 12:19:14
You'll need to construct a valid datetime string from your col2. You'll probably need to use PATINDEX with SUBSTRING since your months and days aren't always 2 digits. You'd be searching for the period with PATINDEX.

Tara
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-16 : 12:28:06
i will, won't i... damn. i was hoping it would be a simple convert thing (the format of the date is really irrelevant) which i tried and it returned the same error.

thanx.

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-16 : 12:33:39
ok if anyone is interested,one can also do this:
'yyyy-mm-dd'
dateadd(y, 0, '2002-03-18')

it works... :)))

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page
   

- Advertisement -