During Select Statement refer to a fields declared name - mysql

I'm currently building a report which at some point compares a few fields and works out the difference between the two.
It first checks which is larger field A or field B and whichever is biggest it then compares to C and tells me the difference. (Other calculations to follow but the answer to this will carry on through the scope of the project)
The problem I've got is A and B are calculated fields and I don't want to keep pasting this code in over and over again for each calculation.
Myself and others will probably refer back to this code regularly and it is already getting very clogged up.
The two existing lines are:
IF(MAX(LEAST(MANFU.height,width)) < 44,0.220,
IF(MAX(LEAST(height,width)) < 68,0.340,
IF(MAX(LEAST(height,width)) < 80,0.400,
IF(MAX(LEAST(height,width)) < 90,0.450,
IF(MAX(LEAST(height,width)) < 122,0.610,
IF(product_code LIKE '%_BB',2.508,'')))))) AS Volumetric_Weight',
and
SUM(boxweight)+SUM(Itemweight)+SUM(packagingweight) AS 'Expected_Weight',
I want to add a field that be able to carry out the following calculation:
IF(GREATEST(Volumetric_Weight,Expected_Weight) > Courier_Weight,'Overweight Item','Underweight Item')
Is there a way to refer to another fields alias?

Related

#Error in Textbox on MS Access Form, when using DMax?

So I have literally used the same code format on 4 other Forms:
Here's the working code from those three forms :
=DMax("ID","tbl_Users")+1
=IIf([lst_DeviceType].[Column](0)="Cell Phone",DMax("DeviceNum","tbl_Cell_Tab","DeviceNum < 70000")
+1,DMax("DeviceNum","tbl_Cell_Tab")+1)
=IIf([frm_type]=0,DMax("DeviceNum","tbl_PC_Lap","DeviceNum < 100000")+1,IIf([frm_type]=1,
DMax("DeviceNum","tbl_PC_Lap","DeviceNum < 50000")+1,DMax("DeviceNum","tbl_PC_Lap","DeviceNum < 40000")+1))
=DMax("DeviceNum","tbl_Printers")+1
The goal here is to pull the current largest number in the Key from the table and from it get the next one in line so as to be calculated and stored for use later in a module that will audit changes to the tables. So I am using the format DMax("DeviceNum", TABLENAME) + 1
My latest form won't accept this format, instead throwing #Error
=DMax("DeviceNum","tbl_ThinClients")
And for the life of me I can not figure out why I keep getting this. I have deleted the textbox, and recreated it.
Here's a snip of the table in design mode
Here's a snip of one of the tables it works with
Any ideas as to why? I mean the only difference I see is that the Printers is a "Large Number" Data type (Values > 80000)
So apparently, though I don't know why, you can't DMax Large Number fields. The solution was to set it to a "Number" and use that.

Access Expression help - Calculated fields

I need some help with an Access expression. I keep getting a syntax error.
I'm trying to get a calculated field from the combination of another calculated field.
Note that the LaserCuttingRate field is also a Lookup field. So it's not a simple entry field. It becomes a selector of the 3 choices.
IIf([LaserCuttingRate]="200",([CuttingTime]*200/60),IIf([LaserCuttingRate]="400",([CuttingTime]*400/60),IIf([LaserCuttingRate]="100",([CuttingTime]*100/60)))
All help appreciated.
Cam
I think you're missing a final close bracket.
There are 6 open brackets ( but only 5 closing brackets )
UPDATE - second issue
Two extra issues
The checks on number either don't need, or shouldn't have double-quotation masks
The final IIF also needs a false clause at the end (in the example below, 0).
Try this - I have put it into an Access database scratch table and it worked. (If relevant, note that I had LaserCuttingRate and CuttingTime set as doubles, as well as the Result Type for the calculated column).
IIf([LaserCuttingRate]=200,([CuttingTime]*200/60),IIf([LaserCuttingRate]=400,([CuttingTime]*400/60),IIf([LaserCuttingRate]=100,([CuttingTime]*100/60),0)))

LookUp not matching properly

So, I have a problem in Report Builder that is just driving me absolutely crazy.
I have two dataset; one called DS_Grades and the other DS_Pupils. I want to do a simple LookUp based on PupilID, a field that is in both datasets, and return a grade from DS_Grades into a Matrix based on DS_Pupils.
The formula I am using is:
=LookUp(Fields!PupilID.Value, Fields!PupilID.Value, Fields!Grade.Value, "DS_Grades")
I have confirmed that:
1) DS_Grades has the right PupilIds
2) There are actually values in the Grades field
3) Both PupilID fields (I.E. in both datasets) are definitely Integers and not text.
Moreover, if I add a calculated field to DS_Grades called "test" and populated with the value 208301, which is a valid PupilID, then I can enter the below formula and it works fine:
=LookUp(208301, Fields!test.Value, Fields!Grade.Value, "DS_Grades")
So, the LookUp itself must be matching properly, which means that the PupilID fields must be causing the problem, but I have quintuple freaking checked them and they definitely have the right values, in the right format. I am at a total loss as to why SSRS thinks that they don't match.
Help please!
Got it! Some filtering was at Dataset Level (instead of query where I normally do it) that was throwing the whole thing out of joint. Removed that, and it's fine.

MYSQL search table, bit fields

I have a table with rows and where one field is a bit-value with 7 digits.
Suppose I have a procedure where I want to select all rows where this bit field equals '0101010', this is easily done by select * where .... and so on.
But: how do I do if I want to allow one/multiple digits of the digits to be either 1 Or 0, i.e I want to get all rows where the bitfield has an entry on the form 1001*1* where the * can be either 1 or 0. So, in this case I would like all entries where the bit field is 1001010, 1001011, 1001110 or 1001111.
select * from TABLE where bit_field in (1001010, 1001011, 1001110, 1001111) would probably work in this example, but if I want to use only the string '1001*1*' as input to the procedure, what then?
.
Any help is very appreciated.
Thanks,
Niklas
Edit: I've tried this: select * from table where field like bit'\\\0'; for getting all entries of the form **0, but that didn't work...
Edit2: It turned out it vas a bit-field, not binary... problem still remain though.
Not a direct answer to your question, per se', but an alternative approach. You mentioned that you didn't want to convert to individual columns because of legacy code. If you do want individual columns and the only thing holding you back is the legacy code, consider the following.
You could add columns for the options and use insert/update triggers to populate them OR you could create a view that splits the bits into separate columns. For new development, you can code to the new columns. Over time, as you modify legacy code you can change it to the new approach. When all the "read" legacy code has been changed, the last step is to change the "write" code to use the new columns rather than the bit column and remove the triggers.
I have a SQL Fiddle demonstrating this here. Note that I only included an insert trigger for brevity.

MS Access Table Design for Employees with different training requirements

Please help with me a conceptual problem I've been trying to figure out for the past 3 days now. I'm trying to use Access to centralize the tracking of training that was previously done on separate excel spreadsheets. I have about ~340 employees that are categorized into 12 different positions all with varying degrees of required training. I have an example below:
Position 1: Class A, Class B, Class C
Position 2: Class A, Class B
Position 3: Class A
Position 4: Class A
As you can see, all 340 personnel require the Class A training. But only some positions require the Class B or even Class C. Right now I have a single table with the individuals name and associated contact information and all 12 possible classes. All I want access to do is store the date they've completed training, nothing else. The problem that I'm running into is that the Date/Time field cannot distinguish between someone that is required to take that class and simply hasn't done it yet (a null value) vs. someone that is not required to take the class and obviously hasn't completed it (also a null value).
What I've tried:
-A query using calculated fields that will enter in the value "NOT REQ" if the job position does not require the training. An example is below:
HAZMAT Inspector: IIf([POSITION]="Load Planner",[HAZ Inspector],"NOT REQ")
Why it doesn't work: Inserting text into the field changes it from a date to a text field so I can no longer use Date functions to determine if training is expired. Also, I cannot edit the field on a form and save it back to the original table due to it being a calculated field.
Possible Solution(?): Use a SQL Update statement in VBA to write the value of a calculated field back into the original table? I still run into the problem that I cannot update the field to begin with on the form...
-Separate Tables for each Position(?): The main problem I see with this is that a lot of positions require the same exact class so I'd be entering in a lot of redundant information.
-Separate Tables for each Class (?): I can see how I'd be safer with this route, but for it to be useful I'd imagine I'd have to write some type of VBA code that says when I assign someone to Position X, his Employee ID is automatically populated in Tables A, B, & C based on his position's training requirements. Is that doable? Is this the best option, or am I just off the mark?
As you already explained, you cannot make entries in a calculated field. You will need a different approach. The approach depends if you display only one employee per form (Single Form) or if you display a list of employees (Continuous Form or Datasheet).
On a Single Form I would simply disable the fields which do not apply
me!txtClassBDate.Enabled = me!txtPosition = 2
You can call this code from Form_Current and possibly in the AfterUpdate of a control used to change the position type.
The other possibility is to use conditional formatting. Select the date-TextBox; then open menu "Format" > "Conditional Formatting..." (I do not know where that is on the ribbons of Acc 2007+). Here you can define the appearance of the control depending on the evaluation of an expression. You can also set the control in a disabled state.