Show distinct id once with multiple rows of data - ms-access

What I have for data:
Bob | 1
Bob | 2
Bob | 3
Jane| 5
Jane| 27
Basically I want to sort this out in either the query or report so I can come out with this as a result:
Bob | 1
| 2
| 3
Jane| 5
| 27
Do I have to use VBA to come up with this solution or is there a workaround either in the query or in the report functionality? I'm just getting used to using Access, so I'm looking for some pointers.

For those that are looking in the future, I had multiple other columns of data that correlated to the one 'name' I wanted to separate out. If you sort by group, you can make the name the 'group name' and all the values will still correlate to that group if you leave them under your details tab in the report.

Related

SSRS: Using tablix with multiple Dataset

I have two datasets:
My First dataset (Students) looks like this:
Student_Name| ID
Jack Luis | 1
Adam Bob | 2
And my second dataset (Exam) looks like this:
Student_ID | Exam | Note
1 | Java | 15
1 | Php | 14
2 | Java | 12
2 | Php | 13
I want to get this in the same Tablix:
Student Name | ID
Jack Luis | 1
Adam Bob | 2
Student_ID | Student Name | Exam | Note
1 |Jack Luis | Java | 15
1 |Jack Luis | Php | 14
2 |Adam Bob | Java | 12
2 |Adam Bob | Php | 13
Thank You Mr alejandro zuleta
but i want the result like this in the same Tablix (using groupin By Name)
Studant Name:Jack Luis
Exam | Note
Java | 15
Php | 14
Studant Name:Adam Bob
Exam | Note
Java | 12
Php | 13
I think this can be solved using LOOKUP function. LOOKUP function joins multiple dataset using a common field in the involved datasets.
Create a tablix and set the DataSetName property to your second dataset.
Drag and drop the fields to the columns you want to show. For the Student Name column use the following expression:
=Lookup(Fields!Student_id.Value,Fields!Student_id.Value,Fields!StudentName.Value,"DataSet21")
In the above expression replace DataSet21 by the actual name of your
first dataset.
It will preview something like this:
UPDATE: Grouping by a header row.
Add a tablix and set your second dataset in DataSetName property. Add Exam and Note fields to the corresponding columns.
Add a Parent Row Group.
In the Tablix group window select the Add group header checkbox and use the following expression:
=Lookup(Fields!Student_id.Value,
Fields!Student_id.Value,Fields!StudentName.Value,"DataSet21")
Delete the first column created by the previous grouping setting.
In the cell above Exam use the following expression:
="Student Name: " &
Lookup(Fields!Student_id.Value,Fields!Student_id.Value,Fields!StudentName.Value,"FirstDataSet")
Now select Exam and Note row and add a row above outside the group.
Type Exam and Note in the corresponding cell above [Exam] and [Note] fields.
Select the three cells in the first row, right click it and select Merge Cells.
It will preview something like this:
If you want to delete the first blank row, you can do it smoothly.
Let me know if this helps.

SSRS Single row for Grouping

I'm working with SharePoint Lists, I have 2 Lists for this issue i.e. Movies & Theatres. Only one list is used tough, because Theatres reference a movie.
(I know this is weird but I'm not actually working with movies and theatres, it's just using an analogy so anyone could understand the problem so let's assume each Theatre only plays a single movie :-P )
So from the Theatres list I create a dataset with following fields: Linked_Movie (Title), Country, Theatre_Number.
I want to create a report that shows a tablix that lists all Movie-titles with all the countries it's shown in and a count of the theatres that are playing that movie. So the tablix should look like example below:
MovieTitle | Country | # of theatres
| |
Movie 1 | Country A | 5
| Country B | 10
SubTotal | 2 | 15
| |
Movie 2 | Country C | 15
SubTotal | 1 | 15
| |
Total | 3 | 30
I have already created a tablix which groups on Linked_Movie first and Country second. Then in the details-section I just count the theatres that play that certain movie in that specific country. To achieve this I created a second dataset with the exact same data so I could use LookUpSet.Length. But even though my calculations are correct the tablix still generates a row for each individual theatre. So my tablix actually looks like example below:
MovieTitle | Country | # of theatres
| |
Movie 1 | Country A | 5
| | 5
| | 5
| | 5
| | 5
.... | ... | ...
So if anyone knows how I would be able to achieve a tablix like the first example that would be greatly appreciated.
If anything is still unclear please don't hesitate to ask.
Kind regards
Gravinco
I was able to solve it by adding a calculated field to the dataset named MovieCountry.
After this I put the expression below as the condition for 'Row visibility' and the visiblity of the '=(Details)' properties:
=iif(Fields!MovieCountry.Value = Previous(Fields!MovieCountry.Value), True, False)
This way I only get a single row for each movie and country combination.
Any questions are always welcome!

Sql serialize columns into one record for search

I would like to create a search feature which looks in multiple tables and columns and return the main idea. For example:
(This is a very simplified scenario, and the real tables have way more columns in which I would like to search)
table 'lead':
id | name | created
1 | john | 1/1/2014
2 | jack | 2/1/2014
table 'notes':
id | lead_id | created | note
1 | 1 | 1/1/2014 | lead added
2 | 1 | 1/2/2014 | some change occurred
3 | 2 | 2/1/2014 | lead added
4 | 2 | 2/2/2014 | some updates
I would like to provide for example the string "2014" which would return lead.id 1,2
Or look for "updates" which would return lead.id 2.
I can either run a join every time the search is performed, or somehow create a view which looks like this:
id | text
1 | john 1/1/2014 1/1/2014 lead added 1/2/2014 some change occurred
2 | jack 2/1/2014 2/1/2014 lead added 2/2/2014 some updates
This way, the search would be in one table and provide a fairly quick results, the "work" is updating the records per id every time tables 'notes' is updated.
I know a view is the best way to do this, but I am not clear on how to serialize a join result into one textual column. Of course it is fairly easy with php (or any back end script) but I was wondering if this can be done in a manner similar to when a view is constantly updated.
Thank you for your assistance.
Use GROUP BY and GROUP_CONCAT functions, somethink like this:
SELECT n.lead_id, CONCAT(l.name, " ", l.created, " ",GROUP_CONCAT(CONCAT(n.`created`," ",n.`note`), " ")) as text
FROM notes n
JOIN lead l ON l.id = n.lead_id
GROUP BY n.`lead_id`
ORDER BY n.`created` DESC
Inner CONCAT forms submessage 1/1/2014 lead added, GROUP CONCAT joins then and the outer CONCAT forms result message john 1/1/2014 1/1/2014 lead added 1/2/2014 some change occurred
Here is SQL Fiddle example

Selecting multiple rows of data from a subtable along with the parent row table in MySQL

I have two tables in my database roughly laid out as below
Client
id | other data
1 | data 1
2 | data 2
3 | data 3
4 | data 4
Employee assigned
id | clientid | employee
1 | 1 | Fred
2 | 1 | Jim
3 | 3 | Peter
4 | 4 | Fred
5 | 4 | Peter
6 | 4 | James
Is there a way to return the client table with all of the employee records from the employee table? Ideally I would want both the id of the row and the employee name so I don't think I can use GROUP_CONCAT to collect more than one column. There is also no guarantee that there will always be an entry for each client in the employee table so it would need to return an empty/null result for those clients.
I have tried two ways to get this so far in php, both are pretty inefficient in one way or another.
(A) The first was to effectively make a new database connection half way through the first one to return the list of employees associated with that client id but obviously that results in a significant number of database connections being made for just one query.
(B) The second was to pull the entire employee table into an array at the beginning of the code and search through that array to pull out the rows relating to that client id which then have the employee name and row id in. Over time this is going to end up with a pretty large array being dumped into php instantly.
Is there some way of pulling this out using just a single SQL query? I'm not all that fussed how the data would come out as I am sure I could sort through it in the php at the other end, but perhaps something along the lines of
Results
id | other data | employees
1 | data 1 | 1,Fred;2,Jim
2 | data 2 |
3 | data 3 | 3,Peter
4 | data 4 | 4,Fred;5,Peter;6,James
If this has been asked before somewhere I apologise, but I have been searching around a bit over the last week and haven't found all that much to help.
SELECT e.*, c.other_data FROM Employee e
INNER JOIN Client c ON e.client_id = c.id
So, what you end up with is all the information from both tables grabbed in one query. So, the data would be:
id client_id Employee other_data
1 1 Fred data 1
2 1 Jim data 1
3 3 Peter data 3
4 4 Fred data 4
5 4 Peter data 4
6 4 James data 4

How do you get the records from single dataset to display onto 4 corners of landscape page? [SSRS]

I am using Microsoft SQL Server Reporting Services 2005
I have a report that when printed I want to display a record in each of the 4 corners of a landscape page.
I am using a single Dataset that returns 1 to many records.
How do I accomplish this with a table or matrix?
For example if I had 6 records in my dataset:
Page 1
|---------------------|
| record 1 | record 2 |
|---------------------|
| record 3 | record 4 |
|---------------------|
Page 2
|---------------------|
| record 5 | record 6 |
|---------------------|
| [empty] | [empty] |
|---------------------|
So I have found a successful way to do this (with help from cdonner's suggestion), have 2 identical table templates and have one display all odd records and the other to display all even records.
This is what Design Mode looks like:
|-------------------|
| table 1 | table 2 |
|-------------------|
Then, what I did was on each tablerow of each table added the expressions to the Visibility > Hidden property of the tablerow:
For Odd Rows:
=RowNumber(Nothing) Mod 2 = 0
For Even Rows:
=RowNumber(Nothing) Mod 2 = 1
The only way I can think of is by using subreports, one showing all even rows, the other one showing all odd rows.
To add Groups to Jon's answer, place tables 1 and 2 within a parent table which performs the grouping:
table-parent
group-row-header // header text..?
group-row-footer // group name is important for below
rectangle
table-child-1 | table-child-2 | etc // =RowNumber("my-group-name")
Note RowNumber must be based on the group so that it resets with each loop.