I am trying to get an Access report to identify if a text field (NH) does not match with the same ID. For example, ID 179 has two rows but each NH is different (12345 & 12346). I am trying to use DCount to count the IDs where the NH does not match if it is the same ID but I cannot figure it out.
Here is an example of my code:
This is supposed to get the ID's that match such as 179 and 179 and check the NH to see if the are the same and return a count if they are not.
CheckValue = DCount([ID], "vTestQuery", "[NH] <> '" & [NH] & "'" And "[ID] ='" & [ID] & "'")
This gives a value to Me.txtColor for a Conditional formatting I have set up if CheckValue has an actual value.
If (CheckValue > 0) Then
Me.txtColor = CheckValue
I also need this go through all the records in the report and get a count on each matching ID with different NHs so I can flag the NHs that are different.
Can someone let me know if I am even on the right track with this and if so a solution to my dilemma.
Thank you very much!
1st EDIT
Sample Data:
+-----+------------+------------+------------+-------------+
| ID | FullName | DateOfServ | AccountNum | NoteH |
+-----+------------+------------+------------+-------------+
| 179 | Test, Jane | 8/1/2015 | 458585 | AAA-1111111 |
| 180 | Test, Paul | 8/1/2015 | 458586 | AAA-2222222 |
| 181 | Test, John | 8/2/2015 | 458587 | AAA-3333333 |
| 214 | Test, Alex | 8/3/2015 | 458588 | AAA-4444444 |
| 214 | Test, Alex | 8/3/2015 | 458588 | AAA-4444445 |
| 215 | Test, Alex | 8/3/2015 | 458589 | AAA-5555555 |
| 215 | Test, Alex | 8/3/2015 | 458589 | AAA-5555555 |
+-----+------------+------------+------------+-------------+
So what I need the report to do is highlight or change text color for the IDs that match but have a different NH For example record 214 has two records with all the same exact data except for the NoteH and I need both those NoteH to be highlighted or the text changed. I have made the NoteH in question both bold. Let me know if this helps.
2nd EDIT
So the query worked for all duplicate IDs with duplicate NoteH, but it still only registers one ID if the NoteH is different. I added an IDCount to show how the query registers each 214 ID as different because of the different NoteH.
Here are the results:
+-----+------------+---------+
| ID | NoteCount | IDCount |
+-----+------------+---------+
| 214 | 1 | 1 |
+-----+------------+---------+
| 214 | 1 | 1 |
+-----+------------+---------+
| 212 | 2 | 2 |
+-----+------------+---------+
I need a way to have the report recognize that 214 is a duplicate field but the NoteH is not the same. It is really close to working everything else you suggested works great!!!
3rd EDIT
SELECT May.ID, Count(May.ID) AS IDCount, FROM May INNER JOIN
Count(CodeRyteCodingResults.[Note Handle]) AS NoteCount
CodeRyteCodingResults ON May.[Accession #] =
CodeRyteCodingResults.[Accession Number]
GROUP BY May.ID;
Use Aggregate Queries and Conditional Formatting
Create separate queries to get counts of unique notes per ID. It will look something like this (I'm using two queries):
UniqueNotesQuery
SELECT ID, NoteH
FROM BaseTable
GROUP BY ID, NoteH
NoteCountsQuery (this queries the first one)
SELECT ID, Count(NoteH) AS NoteCount
FROM UniqueNotesQuery
GROUP BY ID;
Then join this as part of your report query. It will look something like this:
SELECT BaseTable.*, NoteCountsQuery.NoteCount
FROM BaseTable INNER JOIN NoteCountsQuery
ON BaseTable.ID = NoteCountsQuery.ID
In your report, write a rule in the Conditional Formatting of the textboxes. Something like this:
[NoteCount] > 1
These queries above are just written from scratch, so they are untested, and you will need to flesh them out for your project.
References:
Office Support = GROUP BY Clause
Office Support - Conditional Formatting
Related
I have the following table of data from an MDX query that resembles the following:
Account | Location | Type | Person | Amount
ABC | XYZ | AA | Tom | 10
ABC | XYZ | AA | Dick | 20
ABC | XYZ | AA | Harry | 30
ABC | XYZ | BB | Jane | 50
ABC | XYZ | BB | Ash | 100
DEF | SDQ | ZA | Bob | 20
DEF | SDQ | ZA | Kate | 10
DEF | LAO | PA | Olivia | 200
DEF | LAO | PA | Hugh | 120
And I need to add the Amount column for each Account, Location, and Type. If I was using SQL I would perform a query on this data as follows:
Select Account, Location, Type, Sum(Amount) as SumAmmount
From Table
Group By Account, Location, Type
but due to the way we store the data I need to roll-up this data using SSRS. To do that I created a tablix, created a parent group (Which I have called "RollUp") of the default detail group which grouped on Account, Location, and Type and then deleted the detail group so when running the report I get:
Account | Location | Type | Amount
ABC | XYZ | AA | 60
ABC | XYZ | BB | 150
DEF | SDQ | ZA | 30
DEF | LAO | PA | 320
What I need to do now is create a page break so that when I export this SSRS report to excel there are only 1000 rows on each sheet, but I am having trouble writing the expression to split this every 1000 rows. Because I have removed the details group I cannot use the typical expression I would use to page break on a specific row of a dataset (e.g. Group Expression = Floor(RowNumber(NOTHING) / 1000) )
I have tried a few different things like writing some custom code and some running value expressions but haven't been able to figure it out yet.
I did figure out how to do this.
First I created the following custom code in the report definition:
Dim GroupingDummy = "GroupDummy"
Dim RowNumberToReturn = -1
Function PopulateRowNumber(GroupString As String) As Integer
If (GroupString <> GroupingDummy ) Then
GroupingDummy = GroupString
RowNumberToReturn = RowNumberToReturn + 1
End If
Return RowNumberToReturn
End Function
Keeping in mind the grouping I applied to the dataset used the fields Account, Location, and Type, I added a calculated field to my dataset with the name RowNumberCalc and the expression:
=Code.RowNumberToReturn(Fields!Account.Value + Fields!Location.Value + Fields!Type.Value)
Now I could easily create the group that would create a page break at 1000 rows with the expression :
=Floor(Fields!RowNumberCalc.Value / 1000)
I have two mysql tables as
Component
+----+-------------------------+--------+
| OldComponentId | NewComponentId |
+----+-------------------------+--------+
| 15 | 85 |
| 16 | 86 |
| 17 | 87 |
+----+-------------------------+--------+
Formulae
+----+-------------------------+--------+
| id | formula_string |
+----+-------------------------+--------+
| 1 | A+15-16+17 |
| 2 | 16+15-17 |
+----+-------------------------+--------+
I want to replace value of formula_string on the basis of NewComponentId as
Formulae
+----+-------------------------+--------+
| id | formula_string |
+----+-------------------------+--------+
| 1 | A+85-86+87 |
| 2 | 86+85-87 |
+----+-------------------------+--------+
I have tried with following mysql query but its not working
update Formulae fr, Component comp set formula_string=REPLACE(fr.formula_string,comp.OldComponentId,comp.NewComponentId).
Please suggest the solutions
thanks.
There is no easy way to do this. As you observed in your update statement, the replacements don't nest. They just replace one at a time.
One thing that you can do is:
update Formulae fr cross join
Component comp
set formula_string = REPLACE(fr.formula_string, comp.OldComponentId, comp.NewComponentId)
where formula_string like concat('%', comp.OldComponentId, '%')
Then continue running this until row_count() returns 0.
Do note that your structure could result in infinite loops (if A --> B and B --> A). You also have a problem of "confusion" so 10 would be replaced in 100. This suggests that your overall data structure may not be correct. Perhaps you should break up the formula into separate pieces. If they are just numbers and + and -, you can have a junction table with the value and the sign for each component. Then your query would be much easier.
I am new to databases. In mysql database I have one table course. My question is: how to search all related words in both columns course_name and course_description and i need to get all the matched words in both columns? Can any one tell me the sql query for it? I have tried to write a query, but I am getting some syntax errors.
+----------+-----------+-----------------+------------+------------+
| courseId | cname | cdesc | sdate | edate |
+----------+-----------+-----------------+------------+------------+
| 301 | physics | science | 2013-01-03 | 2013-01-06 |
| 303 | chemistry | science | 2013-01-09 | 2013-01-09 |
| 402 | afm | finanace | 2013-01-18 | 2013-01-25 |
| 403 | English | language | 2013-01-17 | 2013-01-24 |
| 404 | Telugu | spoken language | 2013-01-10 | 2013-01-22 |
+----------+-----------+-----------------+------------+------------+
SELECT * from course WHERE cname='%searchtermhere%' AND cdesc='%searchtermhere%'
Adding the percent % makes the search within each value and not just beginning with.
If you want to search exact word
SELECT * FROM course WHERE cname ='word' AND cdesc = 'word'
OR you can also find each value and not just start from begining.
SELECT * FROM course WHERE cname = '".%searchtermhere%."' AND cdesc = '".%searchtermhere%."'
Since you say single parameter i guess. You will get either 'science' as input or 'physics' as input. Then you could simply use 'OR'.
select * from course where cname = (Input) or cdesc = (Input)
I could not quite frame a question that describes my problem right.
But.. this is what I am trying to achieve
There is a table that stores the results of students appearing for exams.
Student Name |Roll Number| Subject | Result
Andy | 111 | Math | Fail
Bob | 112 | Science | Pass
Carl | 113 | History | Pass
Andy | 111 | Math | Pass
Bob | 112 | Science | Fail
Bob | 112 | History | Fail
Carl | 113 | History | Fail
The above being a MySQL table, I would want to delete specific rows that reflect a "bad" result if there is another row that has a "good" result for the same student+subject combination.
ie.. Andy has failed in Math the first time but passed later. So the first row should be deleted. But also, Bob Passed science once, but failed in the second attempt. So the second attempt should be deleted.
The table I would want:
Student Name |Roll Number| Subject | Result
Bob | 112 | Science | Pass
Carl | 113 | History | Pass
Andy | 111 | Math | Pass
Bob | 112 | History | Fail
Carl | 112 | History | Fail
If deleting cannot work, maybe insert the best values into another table and truncate this one.
With the data provided, you can do this as an aggregation query:
select StudentName, RollNumber, Subject,
(case when MAX(Result = 'Pass') = 1 then 'Pass' else 'Fail' end) as Result
from t
group by StudentName, RollNumber, Subject
Use mysql's special multiple-table delete syntax:
delete a
from results a
join results b
on b.roll_number = a.roll_number
and b.subject = a.subject
and b.result = 'Pass'
where a.result = 'Fail'
This will only delete the fail rows if there's a matching pass row. If there are other "good" results than "pass", you will have to tune the conditions accordingly.
Hey all, I am looking for a way to query my database table only once in order to add an item and also to check what last item count was so that i can use the next number.
strSQL = "SELECT * FROM productr"
After that code above, i add a few product values to a record like so:
ID | Product | Price | Description | Qty | DateSold | gcCode
--------------------------------------------------------------------------
5 | The Name 1 | 5.22 | Description 1 | 2 | 09/15/10 | na
6 | The Name 2 | 15.55 | Description 2 | 1 | 09/15/10 | 05648755
7 | The Name 3 | 1.10 | Description 3 | 1 | 09/15/10 | na
8 | The Name 4 | 0.24 | Description 4 | 21 | 09/15/10 | 658140
i need to count how many times it sees gcCode <> 'na' so that i can add a 1 so it will be unique. Currently i do not know how to do this without opening another database inside this one and doing something like this:
strSQL2 = "SELECT COUNT(gcCode) as gcCount FROM productr WHERE gcCode <> 'na'
But like i said above, i do not want to have to open another database query just to get a count.
Any help would be great! Thanks! :o)
There's no need to do everything in one query. If you're using InnoDB as a storage engine, you could wrap your COUNT query and your INSERT command in a single transaction to guarantee atomicity.
In addition, you should probably use NULL instead of na for fields with unknown or missing values.
They're two queries; one is a subset of the other which means getting what you want in a single query will be a hack I don't recommend:
SELECT p.*,
(SELECT COUNT(*)
FROM PRODUCTR
WHERE gccode != 'na') AS gcCount
FROM PRODUCTR p
This will return all the rows, as it did previously. But it will include an additional column, repeating the gcCount value for every row returned. It works, but it's redundant data...