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)
 Default of datetime field is 1/1/1900

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2006-11-02 : 16:24:29
I code a insert function.
If a text box is "" value, data in SQL server become "1/1/1900".
How to void it and make it always display <Null> if "" insert it?

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2006-11-02 : 16:31:51
create table #tmp ( c1 datetime )
declare @tst as varchar
set @tst = ''

insert into #tmp values (@tst)
insert into #tmp values (case(@tst) when '' then NULL else @tst END)

select * from #tmp

drop table #tmp


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-02 : 17:29:51
[code]insert into #tmp values (nullif(@tst, ''))[/code]


KH

Go to Top of Page

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2006-11-02 : 17:45:57
I love it when I learn something new.
Thanks

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-11-02 : 20:12:48
>>If a text box is "" value, data in SQL server become "1/1/1900".

Before sending that to table you should for '' and send as NULL

If trim(textbox)='' then
insert into #tmp values (NULL)
else
insert into #tmp values (yourDate)
End if


Madhivanan

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

- Advertisement -