NULL and dates

  • Is there any way to SET a column to a null value programatically?

     

    I need to remove the date value from a date column after it has been set to some value.

  • I would probably use the value that microsoft uses with a NULL date value (1900-01-01 00:00:00.000)



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • I'm not sure I'm following you here.

    from VB

    SomeField.value = null

    from SQL

    Update MyTable Set MyField = null where MyField = @MyDate

    or

    Update MyTable Set MyField = nullif(@MyDate, MyField)

  • Thanks AJ

    That is what I do now but I then have to edit the redisplay of the field as the users are confused when they see the 1900-01-01 date.

    Just wanted to know if there was some simple way.

    Somewhere I saw that Ctrl-0 will put a null in a date field, but I don't know how to get the user to input that in a field.

    Jack

     

     

  • Ctrl-0 works only in enterprise manager to set a value to null.

    Are you using access or vb to display the information?

    in access you can simply set the value to null and leave it like that.

    In vb I guess you have to set it to "" (if you don't want to show a meaningless date) and then convert it back to a date once the user entered the data (to resend it on the server).

  • I am using Cold Fusion and MS-SQL, and will just have to edit the field before display.

    function blankdate(a){

     var xdate = null

     a.value=xdate

    }

    <input name=StartDate    size=12

      onclick = "blankdate(this)" ondblclick = "newdate(this)"

      value = '#dateformat(tempdate,"dd-mmm-yyyy")#'

      ondblclick="newdate(this)">

  • Try this:

    UPDATE MyTable SET DateField = CAST(NULL AS DATETIME) WHERE ID = 1

    or

    UPDATE MyTable SET DateField = NULL WHERE ID = 1

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply