I'm trying to figure out why my below query is not working.
I have created a calculated field and as part of an IIf() I am looking at doing a LEFT function.
I am hoping to return the First char of the Display Value of a column rather than the Hidden Primary Key.
Just wondering if someone can point me in the right direction?
You can debug this yourself by doing a couple of things. You haven't really provided specific information to what the problem you're facing.
First I would rewrite the query as such to reduce the number of paranthesis and make the intention/logic much clearer, which will also make it easier to debug.
IIf([General Notes] In ("FFA", "Consignment", "CCO", "Hargreaves", "SCRAP"), [General Notes], Left([Supplier_ID],1))
Then start with the following step and identify which field is causing the problem by breaking the query into seperate fields
IIf([General Notes] In ("FFA", "Consignment", "CCO", "Hargreaves", "SCRAP"), [General Notes], "")
Left([Supplier_ID],1)
etc
As for the display value of the column rather than the hidden primary key, [Supplier_ID] sounds awfully like a name that would be given to a key. Perhaps you mean to place something like [Supplier_Name] or [Supplier] etc.
Related
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)))
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.
The following field of a table:
AttorneyEmail(varchar(150), null)
Can have more than one email address, but has this email address in all "helpdesk#dns.org".
I have the following within the Where clause to not include in results:
and aa.AttorneyEmail NOT LIKE ('helpdesk%')
But it still does.
Any help would be appreciated.
Regards,
What you're describing doesn't make much sense. If every row contains the helpdesk address within its AttorneyEmail value (as you say) then a WHERE predicate such as you are trying to use (spelled as #AlexK demonstrates) would exclude all rows. (Also, such a DB structure is pretty ugly.)
In that case, if the point is to strip the helpdesk address from the column value in your results, then you need to do so in the selection list, something like
SELECT REPLACE(aa.AttorneyEmail, 'helpdesk#dns.org', '') AS AttorneyEmail,
...
You may need to adjust that to remove excess delimiters; I can't suggest exactly how because I don't know how you are structuring the values.
I have an Access query that has a some what complex field on it. Basically, I'm searching for a certain value, based on other derived criteria. The function either works, or it gives a #Func! error. There are a few reasons why I may get an error. That is fine, because in those cases I want to return Null.
How can I test and handle a #Func! error from within a query? Also, I tried to wrap the expression in an IsError() method, and handle that case. That still didn't work.
If, for example, you are using Instr with a field that may or may not be null, and that is causing the problem, you can either select only those fields that are not null, or concatenate an empty string with the field.
SELECT Mid(AField & "",Instr(Afield & "","x")) FROM Table
I don't think this is the optimal solution, however, my hope is that the "higher powers that be" within Microsoft that manage Microsoft Access understand exception handling and would provide some way of testing and handling/ignoring errors, where appropriate.
Regardless, in my case I found a hack to the problem. I save the query just as it was and I exported it to a table. Since this was a one-off exercise, I was able to extract the necessary data and then filter out all Null values from the newly created table.
It worked, but it feels like a really poor hack.
OMGGGGG I know im 6 years late but This is the first time I'm posting on a blog because I actually solved the issue!! You have no idea how excited I am. OK so it turns out this is exactly what I was trying to do: Mid(AField,Instr(Afield,"x")). In my case I knew the InStr function did not always find x in Afield, and in those cases ideally I wanted a Null. But What it actually returns is a 0. In access, functions like Right, Left and Mid CANNOT "START" AT 0, They must start at 1 (or -1 I suppose). Which is what is causing the #Func! error!
One solution....if your Instr fuction=0 do one thing other wise do something else.
If I think of another solution, I let you know.
I was able to display data from my MySQL table using this code:
datardr = cmd.ExecuteReader
If datardr.HasRows Then
datardr.Read()
tb_lname.Text = datardr("SURNAME")
tb_fname.Text = datardr("GIVEN")
tb_mname.Text = datardr("MID")
tb_mi.Text = datardr("MIDDLE")
tb_app.Text = datardr("APPELLATION")
tb_prefix.Text = datardr("PREFIX")
tb_sex.Text = datardr("SEX")
tb_status.Text = datardr("STATUS")
End If
However, I noticed that it's not displaying all data coming from these fields. I can only view the SURNAME, GIVEN, MID and MIDDLE but the others are not displayed.. I have double checked my database fields and I'm sure that they're the same and without special characters or whitespaces.
Please help. Thanks!
Here is the exact code that I have => VB2010 and MySQL Code
Alright, here's another answer for you.
I think it's because of your SQL statement in line 21.
I assume you are selecting ONE record (am I right?), so that you can insert the resultant fields into the text boxes. And, you order the result with SURNAME.
Did you double check whether there are already data inside the masterlist table? Especially check, if you already entered the data in every field in every row.
In line 30, you called datardr.Read() method, so the DataReader object datardr will read the first record line it encountered in the result of the sql statement.I think only the four fields of the first record, SURNAME, GIVEN, MID and MIDDLE has data values, and any other fields contain null values. So, you only got these FOUR values appeared inside the text boxes, and any other fields appeared to be blank.
I THINK IT MIGHT BE THE MAIN PROBLEM. Just check whether the data you wanted to be appeared already existed in the database table. OK!
And another suggestion. Don't you think you might need WHERE clause in your SQL statement? Well, you want to display only one record, don't you?
WISH YOU BEST LUCK!!! :-)
I think you better check the sql statement that passed into the command object, cmd.
Maybe you didn't select the entire record with select *.
And, one more recommendation.
If datardr is the DataReader, I highly recommend you NOT to use it. It cause much problems than it serves.
The more flexible approach is to use just the DataTable.
The command object has ExecuteNonQuery method that returns the DataTable object.
It is more flexible and much more easier to use than DataReader. Trust Me...! ;-)