Sending null values in SQL statements

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Sending null values in SQL statements

    I am using an authoring program called Authorware to send
    student scores to ASP pages which send SQL INSERT and
    UPDATE statements to an Access database. Everything
    works well as long as I provide a value for each variable
    that places a value in one of the Access database
    fields. For both the INSERT and UPDATE statements, I
    would like to provide "real" values for some fields and
    null values for the others. For example, I would like to
    INSERT a new record with strings in some fields and null
    values in others. Later, an UPDATE statement may place
    values in some of the null fields and place no value in
    the other null fields.

    I use two ASP pages: one for INSERT and one for UPDATE.
    I would like to use one complete SQL statement in each
    ASP page that specifies all fields. Then, I would
    provide values for some fields and not others. In my
    tests, I'm unable to do this. Is there a workaround?

    Thanks.

    Jim Bowman

    James Bowman Guest

  2. Similar Questions and Discussions

    1. cfgridupdate and null values
      Yeah I have the same problem. It looks like the only solution is to rewrite a custom version cfgridupdate to do my own custom query update. I...
    2. Null Values
      hi how to count null values in an array? tnx
    3. Detecting Null Values
      I have a DataGrid from which the datasource is a SqlDataReader based on a SQL Server Stored Procedure. This SP returns columns will NULL values. ...
    4. Null values enter to SQL
      Hi, I have datagrid filled using SqlDataAdapter. One of the fields is a date field which can be null. When I assign null value I receive the...
    5. Using Field Values in If/Then/Else Statements
      I need to know how to use the value of a table field in a If...Then...Else... statement. I'm using an expression to merge data from several fields...
  3. #2

    Default Re: Sending null values in SQL statements

    You could write a function that formats the value....

    Function FormatDBStr(Field)
    If Not Field = "" Then
    FormatDBStr = "'" & Field & "'"
    Else
    FormatDBStr = "NULL"
    End If
    End Function

    sql = "UPDATE table_name SET field_name=" & FormatDBStr(FieldValue) & "
    WHERE unique_field =something"

    Bob Lehmann



    "James Bowman" <james@jbassoc.biz> wrote in message
    news:10b7a01c44066$5cba4690$a601280a@phx.gbl...
    > I am using an authoring program called Authorware to send
    > student scores to ASP pages which send SQL INSERT and
    > UPDATE statements to an Access database. Everything
    > works well as long as I provide a value for each variable
    > that places a value in one of the Access database
    > fields. For both the INSERT and UPDATE statements, I
    > would like to provide "real" values for some fields and
    > null values for the others. For example, I would like to
    > INSERT a new record with strings in some fields and null
    > values in others. Later, an UPDATE statement may place
    > values in some of the null fields and place no value in
    > the other null fields.
    >
    > I use two ASP pages: one for INSERT and one for UPDATE.
    > I would like to use one complete SQL statement in each
    > ASP page that specifies all fields. Then, I would
    > provide values for some fields and not others. In my
    > tests, I'm unable to do this. Is there a workaround?
    >
    > Thanks.
    >
    > Jim Bowman
    >

    Bob Lehmann Guest

  4. #3

    Default Re: Sending null values in SQL statements

    Thanks Bob. Based on your input, I put this code in the
    asp page and it works well:

    if myvar="NULL" then
    SQL=SQL & "FieldName=NULL,"
    else
    SQL=SQL & "FieldName='" & myvar & "',"
    end if

    SQL is the UPDATE statement. The above code is inserted
    inside the SQL string.

    I note that you use the Function/End Function format. I
    used a simple if-then statement. What's the value of the
    Function/End Function format in this case?

    Thanks.

    James
    >-----Original Message-----
    >You could write a function that formats the value....
    >
    >Function FormatDBStr(Field)
    > If Not Field = "" Then
    > FormatDBStr = "'" & Field & "'"
    > Else
    > FormatDBStr = "NULL"
    > End If
    > End Function
    >
    >sql = "UPDATE table_name SET field_name=" & FormatDBStr
    (FieldValue) & "
    >WHERE unique_field =something"
    >
    >Bob Lehmann
    >
    >
    >
    >"James Bowman" <james@jbassoc.biz> wrote in message
    >news:10b7a01c44066$5cba4690$a601280a@phx.gbl...
    >> I am using an authoring program called Authorware to
    send
    >> student scores to ASP pages which send SQL INSERT and
    >> UPDATE statements to an Access database. Everything
    >> works well as long as I provide a value for each
    variable
    >> that places a value in one of the Access database
    >> fields. For both the INSERT and UPDATE statements, I
    >> would like to provide "real" values for some fields and
    >> null values for the others. For example, I would like
    to
    >> INSERT a new record with strings in some fields and
    null
    >> values in others. Later, an UPDATE statement may place
    >> values in some of the null fields and place no value in
    >> the other null fields.
    >>
    >> I use two ASP pages: one for INSERT and one for
    UPDATE.
    >> I would like to use one complete SQL statement in each
    >> ASP page that specifies all fields. Then, I would
    >> provide values for some fields and not others. In my
    >> tests, I'm unable to do this. Is there a workaround?
    >>
    >> Thanks.
    >>
    >> Jim Bowman
    >>
    >
    >
    >.
    >
    James Bowman Guest

  5. #4

    Default Re: Sending null values in SQL statements

    The function can be reused so you don't have to keep writing the same,
    lengthier code over and over.

    Bob Lehmann

    "James Bowman" <james@jbassoc.biz> wrote in message
    news:1222401c44286$d8201a90$a601280a@phx.gbl...
    > Thanks Bob. Based on your input, I put this code in the
    > asp page and it works well:
    >
    > if myvar="NULL" then
    > SQL=SQL & "FieldName=NULL,"
    > else
    > SQL=SQL & "FieldName='" & myvar & "',"
    > end if
    >
    > SQL is the UPDATE statement. The above code is inserted
    > inside the SQL string.
    >
    > I note that you use the Function/End Function format. I
    > used a simple if-then statement. What's the value of the
    > Function/End Function format in this case?
    >
    > Thanks.
    >
    > James
    >
    > >-----Original Message-----
    > >You could write a function that formats the value....
    > >
    > >Function FormatDBStr(Field)
    > > If Not Field = "" Then
    > > FormatDBStr = "'" & Field & "'"
    > > Else
    > > FormatDBStr = "NULL"
    > > End If
    > > End Function
    > >
    > >sql = "UPDATE table_name SET field_name=" & FormatDBStr
    > (FieldValue) & "
    > >WHERE unique_field =something"
    > >
    > >Bob Lehmann
    > >
    > >
    > >
    > >"James Bowman" <james@jbassoc.biz> wrote in message
    > >news:10b7a01c44066$5cba4690$a601280a@phx.gbl...
    > >> I am using an authoring program called Authorware to
    > send
    > >> student scores to ASP pages which send SQL INSERT and
    > >> UPDATE statements to an Access database. Everything
    > >> works well as long as I provide a value for each
    > variable
    > >> that places a value in one of the Access database
    > >> fields. For both the INSERT and UPDATE statements, I
    > >> would like to provide "real" values for some fields and
    > >> null values for the others. For example, I would like
    > to
    > >> INSERT a new record with strings in some fields and
    > null
    > >> values in others. Later, an UPDATE statement may place
    > >> values in some of the null fields and place no value in
    > >> the other null fields.
    > >>
    > >> I use two ASP pages: one for INSERT and one for
    > UPDATE.
    > >> I would like to use one complete SQL statement in each
    > >> ASP page that specifies all fields. Then, I would
    > >> provide values for some fields and not others. In my
    > >> tests, I'm unable to do this. Is there a workaround?
    > >>
    > >> Thanks.
    > >>
    > >> Jim Bowman
    > >>
    > >
    > >
    > >.
    > >

    Bob Lehmann Guest

Posting Permissions

  • You may not post new threads
  • You may 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