Professional Web Applications Themes

ASP SQL Insert NULL Date Value - ASP

Hello, I've been pulling my hair out trying to figure this out. Thank you in advance for taking the time to look at this. I'm trying to insert a NULL value into my SQL Server 2000 database. I have a datetime field called 'ProcedureDate' that is allowing NULL values. When inserting a NULL, SQL always puts the date 1/1/1900. I'm trying to leave this field blank if no date is entered. Thank's Again ! Chad ------------------------ Here is my ASP Code that sets a NULL value if there is no date entered: <% If Request.Form("sProcedureDate1") = "0" OR Request.Form("sProcedureDate2") = ...

  1. #1

    Default ASP SQL Insert NULL Date Value

    Hello,

    I've been pulling my hair out trying to figure this out. Thank you in
    advance for taking the time to look at this.

    I'm trying to insert a NULL value into my SQL Server 2000 database. I
    have a datetime field called 'ProcedureDate' that is allowing NULL
    values. When inserting a NULL, SQL always puts the date 1/1/1900. I'm
    trying to leave this field blank if no date is entered.

    Thank's Again !

    Chad

    ------------------------

    Here is my ASP Code that sets a NULL value if there is no date entered:

    <%
    If Request.Form("sProcedureDate1") = "0" OR
    Request.Form("sProcedureDate2") = "0" OR Request.Form("sProcedureDate3")
    = "0" Then

    sProcedureDate = NULL

    Else

    sProcedureDate = Request.Form("sProcedureDate1") & "/" &
    Request.Form("sProcedureDate2") & "/" & Request.Form("sProcedureDate3")

    End If
    %>

    ------------------------

    Here is my ASP SQL Insert Code:

    <%
    rsInsert = "INSERT into tblProceduralInfo (" &_
    "PatientID, " &_
    "ValvePlacementDuring, " &_
    "ValvePlacementIn, " &_
    "PatientAdmittedTo, " &_
    "ProcedureDate, " &_
    "StartTime, " &_
    "EndTime " &_
    ")"

    rsInsert = rsInsert & "VALUES" &_
    "('" & Request.Form("sPatientID") &_
    "', '" & Request.Form("sValveDuring") &_
    "', '" & Request.Form("sValveIn") &_
    "', '" & Request.Form("sPatientAdmitted") &_
    "', '" & sProcedureDate &_
    "', '" & sStartTime &_
    "', '" & sEndTime &_
    "')"

    objConn.Execute(rsInsert)
    %>

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Chad S Guest

  2. #2

    Default Re: ASP SQL Insert NULL Date Value

    Chad S wrote:
    > Hello,
    >
    > I've been pulling my hair out trying to figure this out. Thank you in
    > advance for taking the time to look at this.
    >
    > I'm trying to insert a NULL value into my SQL Server 2000 database. I
    insert into table(datecol)
    values (null)

    HTH,
    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] Guest

  3. #3

    Default Re: ASP SQL Insert NULL Date Value

    <%
    If Request.Form("sProcedureDate1") = "0" OR
    Request.Form("sProcedureDate2") = "0" OR Request.Form("sProcedureDate3")
    = "0" Then

    sProcedureDate = "NULL"

    Else

    sProcedureDate = "'" & Request.Form("sProcedureDate1") & "/" &
    Request.Form("sProcedureDate2") & "/" & Request.Form("sProcedureDate3") &
    "'"

    End If
    %>

    Then remove the single quotes:

    "', " & sProcedureDate &_
    ", '" & sStartTime &_

    In addition, I *STRONGLY* urge you to use YYYYMMDD format instead of this
    confusing and ambiguous m/d/y or d/m/y format.

    --
    Aaron Bertrand
    SQL Server MVP
    [url]http://www.aspfaq.com/[/url]


    Aaron Bertrand - MVP Guest

  4. #4

    Default Re: ASP SQL Insert NULL Date Value

    Bob,
    Quick OT question.... You planning on being at the 2004 MVP Summit in
    April. I'm gonna plan on it,... so I could keep an eye out for you if you
    are there.

    --

    Phillip Windell [MCP, MVP, CCNA]
    [url]www.wandtv.com[/url]


    Phillip Windell Guest

  5. #5

    Default Re: ASP SQL Insert NULL Date Value

    Phillip Windell wrote:
    > Bob,
    > Quick OT question.... You planning on being at the 2004 MVP
    > Summit in April. I'm gonna plan on it,... so I could keep an eye out
    > for you if you are there.
    No, I can't make it - unfortunately.

    It would have been ok for you to email me offline with this question.

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] Guest

  6. #6

    Default Re: ASP SQL Insert NULL Date Value

    Ok, I just added the your adjusted address to my list in case I need it in
    the future.


    --

    Phillip Windell [MCP, MVP, CCNA]
    [url]www.wandtv.com[/url]


    "Bob Barrows [MVP]" <reb01501NOyahoo.SPAMcom> wrote in message
    news:OTci6qx9DHA.2184TK2MSFTNGP09.phx.gbl...
    > Phillip Windell wrote:
    > > Bob,
    > > Quick OT question.... You planning on being at the 2004 MVP
    > > Summit in April. I'm gonna plan on it,... so I could keep an eye out
    > > for you if you are there.
    >
    > No, I can't make it - unfortunately.
    >
    > It would have been ok for you to email me offline with this question.
    >
    > Bob Barrows
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >

    Phillip Windell Guest

Similar Threads

  1. Insert NULL not Blank into MySQL with PHP Script
    By Mark Davenport in forum PHP Development
    Replies: 3
    Last Post: June 3rd, 10:18 PM
  2. 500 NULL error on DB Insert (SQL Server)
    By jgmoore in forum Coldfusion Database Access
    Replies: 3
    Last Post: May 20th, 01:15 AM
  3. odbc insert null error
    By bflophil in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: February 18th, 10:09 PM
  4. INSERT Null value problem
    By Targa in forum ASP Database
    Replies: 8
    Last Post: May 15th, 03:50 AM
  5. How insert null in numerics fields?
    By Vilmar Braz„o de Oliveira in forum ASP Database
    Replies: 5
    Last Post: January 8th, 06:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139