Solved

MS SQL DEFAULT DATE 1/1/1900

Posted on 2001-07-22
7
498 Views
Last Modified: 2008-03-03


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
Comment
Question by:iyiola
7 Comments
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
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
 

Author Comment

by:iyiola
Comment Utility
hongiun,
The field allows default values.
The problem is that SQL server is not taking "NULL" cos  the datatype is datetime



0
 
LVL 2

Expert Comment

by:xinger
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 33

Accepted Solution

by:
hongjun earned 20 total points
Comment Utility
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
 
LVL 1

Expert Comment

by:loveneesh_bansal
Comment Utility
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
 
LVL 2

Expert Comment

by:Lunchy
Comment Utility
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
 
LVL 2

Expert Comment

by:Lunchy
Comment Utility
Force accepting hongjun's answer.
It is pretty clear you can't assign a string to a date field.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now