working with floats mysql - mysql

i am customizing a Word Press plugin named Gravity Forms, now the plugin is using a column as datatype float
now i created a totally new interface for displaying the details of an entry that is submitted, i have a set of checkboxes in the form, what Gravity Forms is doing it is adding the field_number as a floats and then the value against it
now for one set of checboxes on my form it is using the field_number as 2 now the 2 remains constants no matter how many checkboxes are selected, and after that comes some points values e.g 2.1 for a specific value and then 2.2 for a specific value and so on upto n times depending on the numbers of checkboxes in the form. please see the below image for more clarification!
Important Note! i cant change the datatype of float as something else e.g vahrchar or decimal it totally messes up the plugin
now i did struggled with getting the float values, because float are not that reliable and easy to use i have seen other blogs where people prefer double or decimal over it
my main problem was this query,
SELECT value FROM wp_rg_lead_detail WHERE lead_id=".absint( $lead['id'] )." and field_number=2.4
now running this query i did not get any result, so what i did is modified my query and passed the value as decimal!
SELECT value FROM wp_rg_lead_detail WHERE lead_id=".absint( $lead['id'] )." and CAST(field_number AS DECIMAL) = CAST(2 AS DECIMAL)
now this query worked just fine and returned the number of rows, but the problem is it is missing some data and not returning all data. like if i have 5 rows as you can see the in the image above its returns only three rows and skips the two rows! any help?

If you want compare with 2 could be you need a truncate instead of a cast eg:
SELECT value
FROM wp_rg_lead_detail
WHERE lead_id=".absint( $lead['id'] )."
and truncate(field_number,0) = 2

Related

MS Access Expression That Includes Dynamic Field Names

I have a crosstab query which returns results based on consumer demand for a bunch of material numbers. The material numbers become my field names in the crosstab query, and later the values from those fields are displayed in a form.
In the form, I display the value in a textbox. There are a couple of these textboxes where I need to sum the total of two or more values from these fields. Not a big deal it's a simple expression. For example (in the Control Source property): =[H123457] + [H123456].
This works well UNTIL there is no demand for a particular material number. In this case, the field doesn't show up in the crosstab query and I'm left trying to sum two fields where one doesn't exist.
I've tried IIf(IsError([H123456]), 0, [H123456]), Null expressions, Nz function, etc but cannot figure out how to dynamically solve the #Name issue that ends up populating the text box.
Essentially what I want is for a 0 value for the field that doesn't exist, so I can add it to the value where the field DOES exist - is this possible?
Regards!
June7 provided the answer in the allenbrowne.com link. Essentially, you need to add all of the possible field names to the Column Headings property in the crosstab query property window. Then it's a simple matter of adding an Nz() function to handle null values.
Thanks June7!

Adding multiple number fields together based on yes/no answers in Access

It's been years since I've worked with Access/VBA so most of what I learned has been forgotten. That said, I'm trying to create a table with multiple numeric fields that I would like to add together on a form based on whether or not someone selected yes/no.
I have the following type of setup
Field_A (Number)
Field_A_Check (yes/no)
Field_B (Number)
Field_B_Check (yes/no)
Field_C (Number)
Field_C_Check (yes/no)
If someone clicks yes next to Field_A and Field_C, I want to calculate the total in Field_A and Field_C together and capture that total on a form text box. If someone else clicks yes next to Field_B only, I want to calculate just that number for that field only.
I've done a nested iif statement on the form, but it became so convoluted, I'd get lost. It also doesn't seem like the best way to tackle this either. Any additional help would be appreciated.
Thank you.
Since true & false boolean field values are represented by the integers -1 & 0 respectively, you can use the following single expression to calculate the total:
=-Field_A*Field_A_Check-Field_B*Field_B_Check-Field_C*Field_C_Check
Here, if any of the _Check fields are unchecked (false), the field value will be zero thus omitting the corresponding value from the sum.

How to Sum value of fields in a ms access form

I have a form where in need to calculate sum of multiple text boxes.
example: i have two text boxes A=10.15 and B= 15.60. I want to sum their values in text box 'c'. I tried using the sum function but results in '#Error' and '+' which appends the two values '10.1515.60'.
Any Suggestions???
Thank you
Tried this =Val[TextBoxA.value]+Val[TextBoxB.value]
it works, when I try to sum two textboxes in another textbox, at first Access concatenated the values but with this formula access let you sum both values.
Set the Control Source of textbox C (without the quotes).
'=[TextBoxA]+[TextBoxB]'
Make sure the textbox format is Number. Leaving it blank concatenates the values.
The SUM function is for totaling the values in the same field, across multiple records.
To calculate the total of two textboxes, set the Control Source property of textbox C to the following (include the = sign)
= NZ([A],0) + NZ([B],0)
The NZ function gracefully handles NULLS by changing them to 0.
Note that textbox C will be unbound, so the sum will not be stored in your table (but it is not a good practice to store calculations, so that should be OK).

What ID does a ComboBox reference?

I am attempting to maintain and fix a horribly out-of-date CRM designed by an ex-employee ~4-5 years ago in Access 2007. I have brought it into Access 2013 and fixed a ton of stuff up, but I am still running into many problems.
I spent a good 4 hours today attempting to figure out why certain values didn't line up. These values were being pulled from a SELECT statement on a Combo Box over a stored Query which simply returns a table with a few extra rows. Great.
However this value (a number) doesn't appear to correlate with what we expect. I enter in one value, save the ticket, and a completely different value gets stored into the table. Opening up the ticket, I see the value that I expect. Digging deeper, I found the following difference:
Set value_1 = Me.RegistrationID // What's being stored in the table
Set value_2 = Me.RegistrationID.Column(0) // What we expect
Surprise surprise! This is a Combo Box and some value is being stored in the table. The Control Source is "RegistrationID" and the Row Source is the query in question.
However I do not know what it is! This specific value correlating to the Combo Box appears to pull the correct data when we later open the tickets. However I have a strong feeling that this could be why many tickets from before one of the rows was deleted all appear to have invalid RegistrationID's.
How badly can this break?
How easily can we correct tens of thousands of tickets?
How can I fix this to store the correct value?
This is what I expect is happening.
Your combo box row source is based on a Select query which returns and displays multiple rows. For example:
Select RegistrationID, CustomerID, CustomerName From MyTable;
The Control Source for the combo box is bound to RegistrationID which is part of the Forms Record Source.
The issue is the bound column. If we set the bound column in our example to 1, then we get the behavior your are describing with:
Set value_1 = Me.RegistrationID - Set's value to CustomerID (may appear correct)
Set value_2 = Me.RegistrationID.Column(0) - position 0 from our query (RegistrationID)
Further building on our query example, you can say:
Me.TextBox1 = Me.RegistrationID.Column(0) - RegistrationID
Me.TextBox2 = Me.RegistrationID.Column(1) - CustomerID
Me.TextBox3 = Me.RegistrationID.Column(2) - CustomerName
The RegistrationID is what normally should be stored in the table.
As long as your form shows any values that directly relate to this RegistrationID you're fine.
I would start by checking to see under the format setting to see if column widths are set properly and I would also check under the data section to see if the bound column is correct. I might also throw in an after update macro/vba sub routine that saves the record. Hope this helps.

Odd results in MS Access Query using a DSUM function and parameters

I've just started using MS Access this month and I have a very odd bug. I'm trying to create a query that searches for records in a table that have a maxBenefit (a dsum from a different table's field, with a one to many relationship) within a certain range. I'm using the DSUM function to get the maxBenefit because the table has a dailyBenefits field that need to be added together.
Here is my function:
maxBenefitOfQuote: Nz(DSum("[wholeYearBenefit]","tblDisabilityQuoteDailyBenefits",
"[quoteID] = " & [tblDisabilityQuotes].[ID]))
I know the function works because it produces the correct values. The query also takes in two parameters from a form to create a range for maxBenefits.
I limit the results with this criteria:
>=[Forms]![frmDisabilityFindSimilarQuotes]![minBenefitTotal] And
<=[Forms]![frmDisabilityFindSimilarQuotes]![maxBenefitTotal]
The problem is I get very odd results from the query with maxBenefits outside the range or not returning records with maxBenefits inside the range. If I set the minBenefitTotal to 0 and the max BenefitTotal to 100000000 I get no records returned from the query. If I set the minBenefitTotal to 0 and the maxBenefitTotal to 999999999 I get all the proper records.
Any ideas why this is happening? Thanks in advanced.
First,
Try wrapping both of your inputs in a call to CCur:
>=CCur([Forms]![frmDisabilityFindSimilarQuotes]![minBenefitTotal]) And
<=CCur([Forms]![frmDisabilityFindSimilarQuotes]![maxBenefitTotal])
Next,
If you omit the actual form inputs, and hard-code numbers into the criteria, does it work?
For Example: (>= 0 and <= 100000000)
If that worked... It feels like a string -> number conversion issue. Make sure all string input is actually a number (via CCur()) before sending it into the query.