• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 513
  • Last Modified:

MS SQL DEFAULT DATE 1/1/1900



I want to prevent the default value of 1/1/1900 from beign inserted into the date field in the table

How do I change this value to NULL?
I tried this but didn't work

Any suggestion will help
====================================


sTHE_DATE=Request.Form("THE_DATE")
If sTHE_DATE="" Then
sTHE_DATE="NULL"
End If

sql to update.....................

0
iyiola
Asked:
iyiola
1 Solution
 
hongjunCommented:
Make sure that the field is not set to be the default date when this table is created. Also make sure that this field allows NULL values.

hongjun
0
 
iyiolaAuthor Commented:
hongiun,
The field allows default values.
The problem is that SQL server is not taking "NULL" cos  the datatype is datetime



0
 
xingerCommented:
I think a CASE expression embedded into your UPDATE SQL is a possibility. I'm not sure of the exact syntax off the top of my head, but it is something like the following.

sTHE_DATE = sTHE_DATE=Request.Form("THE_DATE")

sUPDATE_SQL = "UPDATE TheTable SET TheDateField = CASE " & sDATE & "WHEN '' THEN NULL ELSE " & sDATE & " END ..."
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hongjunCommented:
Ok. Does the field allow NULL field? If yes you can insert a NULL field for that. Note that NULL is allowed but the string "NULL" is not allowed.


Try this

<%
sTHE_DATE = Request.Form("THE_DATE")
If sTHE_DATE = "" Then
    strSQL = "update your_table set your_date = null"
else
    strSQL = "update your_table set your_date = '" & sTHE_DATE & "'"
End If

objConn.Execute(strSQL)
%>


hongjun
0
 
loveneesh_bansalCommented:
There is no way you cannot stop the sql server to take the 1/1/1900 value but you can solve you problem by making the field varchar and later on in the programming part convert this value into the date by using the date functions. Because when i have the similar problem then i solve this by this way only.

bye

 
0
 
LunchyCommented:
Hi iyiola

In the interest of maintaining the database of questions, it would be good if you could resolve your question.  Your options at this point are:

1. Award points to the Expert who provided an answer, or who helped you most. Do this by clicking on the "Accept Comment as Answer" button that lies above and to the right of the appropriate expert's name.

2. Award points to multiple experts--If you wish to award multiple participants, you can do so by creating a zero point question in the Community Support topic area, include this link and tell them which experts you'd like to award what amounts.

3. PAQ the question because the information might be useful to others, but was not useful to you. To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

4. Delete the question because it is of no value to you or to anyone else. To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

If you elect for option 2, 3 or 4, all you need to do is post right here as a comment, and I will take care of the rest.

PLEASE DO NOT AWARD THE POINTS TO ME. We also request that you review any other open questions you might have and deal with them as necessary.

Lunchy
Friendly Neighbourhood Community Support Moderator
Community Support:
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
0
 
LunchyCommented:
Force accepting hongjun's answer.
It is pretty clear you can't assign a string to a date field.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now