Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to make my sql work with zero values

    How to make my sql work with zero values


    I have a valid sql clause as follows

    strSQLSupplier = "UPDATE Products SET Stock = Stock + " & Me.Quantity & " WHERE ProductID=" & Me.Productid

    The above SQL clause works only if the field

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: how to make my sql work with zero values

    I bet the initial value of Stock for a new item is Null and not zero. Any math with Null produces a Null result.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to make my sql work with zero values

    It sounds like the value of the stock field is not zero, but is null. Null is not zero and null plus any number is null.

    You will probably need to do two things. First change the table definition so that the default for the stock field is zero. Second, you will need to update all of the records in your table with null stock to zero.
    Legare Coleman

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to make my sql work with zero values

    Yeas you are right, the initial value is Null. Is there any way on Access to avoid that?
    Best regards

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Tennessee
    Posts
    194
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to make my sql work with zero values

    set the default value of the field to zero

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: how to make my sql work with zero values

    Or change your SQL to this:

    strSQLSupplier = "UPDATE Products SET Stock = Stock + " & Nz(Me.Quantity, 0) & " WHERE ProductID=" & Me.Productid
    Charlotte

  7. #7
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: how to make my sql work with zero values

    The best way is to set the DefaultValue of this field to 0 in your table. If you can't, then use the NZ function (Null-to-Zero):
    = NZ ([Stock],0) + ..........
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

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