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)
 want to avoid default date to be inserted

Author  Topic 

ibin
Starting Member

26 Posts

Posted - 2009-10-14 : 08:29:08
while inserting data into a datetime column for empty string it is taking the default datetime. How to avoid this and insert null

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-14 : 08:32:11
Sorry but that sounds to make no sense.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

rocknpop
Posting Yak Master

201 Posts

Posted - 2009-10-14 : 08:34:40
Check for empty string in the proc(if you have one) and insert NULL
OR
pass "NULL" to your sql query from your app
OR
if you have a proc do not pass the param if it is empty and make that param to accept default NULL
--------------------
Rock n Roll with SQL
Go to Top of Page

ibin
Starting Member

26 Posts

Posted - 2009-10-14 : 08:40:06
create table temp
(col1 datetime,
col2 datetime)
Insert into temp Values('','')

now table temp would contain
col1
1900-01-01 00:00:00.000 1900-01-01 00:00:00.000
Go to Top of Page

ibin
Starting Member

26 Posts

Posted - 2009-10-14 : 08:40:56
how to avoid the above and just leave the col1 and col2 to be empty. Hope i make sense now........
Go to Top of Page

ibin
Starting Member

26 Posts

Posted - 2009-10-14 : 08:44:06
well thanks... how stupid i am...
Go to Top of Page

rocknpop
Posting Yak Master

201 Posts

Posted - 2009-10-14 : 08:44:10
DECLARE @T TABLE
(
ID INT IDENTITY(1,1),
COL1 DATETIME,
COL2 DATETIME
)
INSERT INTO @T VALUES (NULL,NULL)
SELECT * FROM @T

Why cannot you simply insert NULL. Are you talking about a parameter which is empty?

--------------------
Rock n Roll with SQL
Go to Top of Page
   

- Advertisement -