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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Place NULL into SQL Server Datefield

Status
Not open for further replies.

PDL

IS-IT--Management
Dec 11, 2000
36
US
OK... what's the secret?? I have a plain date field in SQLServer. I want it to be blank! If I put in a blank, I get 01/01/00 back (starting date for SQLSever).
 
I remember having this exact same problem with SQL Server and I kicked myself when I figured it out. You just set the date equal to null. An update query for example:

<cfif Len(FORM.Date) NEQ 0>
Date = #CreateODBCDate(FORM.Date)#,
<cfelse>
Date = null,
</cfif> Andrew
amayer@sonic.net
 
If that doesn't work, here's another option that i have right in my SQL update statement:

<cfquery NAME=&quot;query&quot; DATASOURCE=&quot;dsn&quot;>
UPDATE tablename
<cfif #FORM.date# IS &quot;&quot;>
SET date = Null,
<cfelse>
SET date=#CreateODBCDate(FORM.date)#,
</cfif>
moreValues='#FORM.moreValues#'
</cfquery>
 
Don't forget to set the field in SQL Server to allow nulls!!!

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top