Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting Dates and not inserting 01/01/1900

Status
Not open for further replies.

AppzDev

MIS
Oct 9, 2002
57
US
It seems like, in my scouring of the net, that this is a common problem with SQL servers. My question is, how do i fix it?

I have a simple insert statement that does exactly what it is supposed to do...insert values that are input in text boxes. Some of those text boxes of course, are date fields that do not *need* to be valued. So, as most of you know, if a date is not entered into a datetime field, SQL defaults it to 01/01/1900.

I haven't found a simple and/or conclusive way to combat this.

Below is my sql string. Pretty simple and straightforward. No joins or anything...

Dim myInsertLabs as String = "INSERT INTO tblPatient_Values (pt_id, visit_date, appt_date, dre_date," & _
"lipid_prof_date, hgba1c_date, total_chol, hdl, ldl, triglycerides, hgba1c, values_comments1)" & _
"VALUES ('"& patient_id.text & "', '"& visit_date.text & "', '"& appt_date.text & "', '"& dre_date.text & "', " & _
"'"& lipid_prof_date.text & "', '"& hgba1c_date.text & "', '"& total_chol.text & "', '"& hdl.text & "', '"& ldl.text & "', " & _
"'"& triglycerides.text & "', '"& hgba1c.text & "', '"& value_comments1.text & "')"

Again, if the user does not enter a date, how can i make it so the SQL server DOES NOT put a 01/01/1900 in the field?? Besides changing the datatype on the SQL side.

Thanks for any help.

dc~
 
You would need to look at the field they enter their date value in. If it's empty (or 12/31/1899), then in your INSERT statement you'll need to put a NULL in that column. Note that your database schema must allow that column to contain nulls.

Often, your application code will need two variables to hold a single value -- one for the value itself, and another boolean to indicate if it's null or not.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top