Access Crosstab Report Update Columns - ms-access

I have a query running in MS Access which displays employees in the first column and then pivots the status of their training tasks in the remaining columns. Statuses are simply given as completed, not required or required as shown below:
Employee Computer Business Communication
=========================================
samiro05 C NR R
bobmarley NR NR C
einstein NR R R
With this query I can run a report and change the design to be better looking and conditionally formatted to highlight areas where training is required (R). If I add more people to the source tables along with their training I can press refresh on the report and it will add a new line for the employee name just as the crosstab query now has a new row for the new employee's training. However, if I add a new training task, say Science, and update the employees' training to include Science then my crosstab query looks like this:
Employee Computer Business Communication Science
=================================================
samiro05 C NR R C
bobmarley NR NR C NR
einstein NR R R C
sheldon C C R C
...but my report when refreshed looks like this:
Employee Computer Business Communication
=========================================
samiro05 C NR R
bobmarley NR NR C
einstein NR R R
sheldon C C R
Is there a way to get the columns of my crosstab query to change within my report as my crosstab query columns increase/decrease just by refreshing the report rather than having to create the whole report again each time I add a new training/each time a new column is added or taken away from my crosstab query?
Many thanks for any help you can give with this. I will add my thoughts on how to solve this in the comments below.

Related

Recursive query using JPA to get employee hierarchy

I am trying to find a way to get the employee hierarchy in an organization using JPA and Spring boot.
The problem is similar to the following link
Similar Data Model
If A reports to B and B reports to C and C reports to D,
For employee B i need the output to be B->C->D.
The following the Recursive query in Mysql
WITH RECURSIVE Employee_path(id,Name,bid) AS(
SELECT id,Name,bid
FROM Employee
WHERE id = 1005
UNION ALL
SELECT e.id,e.Name,e.bid
FROM Employee_path AS cp JOIN Employee AS e
ON cp.bid = e.id
)
SELECT * FROM Employee_path ORDER by bid ASC;
Since I am new to JPA I am unable to get the solution in an optimised way(I am not getting how to approach this problem)
I just added a recursive way of getting it in an optimised way.
PFL for the repo
For my git repo
Consider following example as MySQL snapshot
id name bid
1 A 0
2 B 1
3 C 2
4 D 1
I want to get the Reporting manager line for person C
Which should return string C->B->A

Group in SSRS Report

I have some issue in my sales report . I want to make a report like this, in which two columns are there..
Team TotalSales
Team A 1000
a1 500
a2 500
Team B 400
Team C 800
Total 2200
here a1 and a2 are sub part of Team A.1000 is sum of a1 and a2 ToltSales.
Please help..
Start with the Table Wizard - set your team name to the grouping field, and your values in the details field. Enable totals lines and the layout you'd prefer. The resulting table will be pretty close to what you need logic-wise, you'll just need to format it how you'd like.
I'd advise taking some time to look at how the wizard sets up grouping properties, as the wizard won't be useful at all when you need to get into very complicated tables with multiple levels of grouping.

Build reports dynamically in ssrs

I have data in my database table which looks similar to the data below :
Time Name Sales
Aug-11 A 33
Aug-12 B 34
Aug-13 C 31
Aug-14 D 39
Sep-11 A 99
Sep-12 B 34
The requirement is that I need to build a report for A details ,another report for B details ,and another for C details and so on. There Could be a D and E added to the database table next month and some more data the month later...
I want to know if there is a way that I can create the reports dynamically , rather than creating a report for A, B and C now and then going into the report and creating another report for D and E next month and soo on..
Please let me know.
Create a report with a parameter #Name , Create a Drop down List using query something like
SELECT DISTINCT Name
FROM Table_Name
for user to select A, B or C and in parameter properties you can choose it to be a multiple selection and create a query something like
SELECT Time, Name , Sales
FROM Table_Name
WHERE (Name IN (#Name_Pram))
You will have to create 2 Data sets one for the drop down list from where users will select Name parameter, selected value(s) will be passed to the above query , One report will show details for any selected values.

Populating with '0' when Data in SSRS Does not exist

I'm trying to create a report in SSRS where I have a matrix, which has gender as the column headings and specifically defined agegroups as the rows. The report is sorted by date (ie, the records being displayed are filtered by the modifedAt value). My problem is that i wish for all of the age group categories to be displayed, even if the dataset does not return any data for that row.
So, for example, if i set the date to be a date where there are no db rows where there are Age5-16 children in - I still want to display the category name, but just have the cells related to that row to display '0'. Instead, the report just drops the whole row because, obviously the query returns no data.
Is the solution to have a separate dataset that brings back the entire list of categories and then somehow fit them together? I'm stuck here so any help is appreciated!
I can think of a few ways to do this:
DataSet level
Instead of just returning the relevant data in the underlying data in the DataSet, include all the categories you want to display in all cases.
e.g. For a database query it might be the difference between an inner and left join, i.e. going from something like:
select *
from AgeGroup
inner join MyData on ...
to:
select *
from AgeGroup
left join MyData on ...
So the report always has all the age groups to display. Where there are NULL values, just display 0.
I think this is the best option if you have control over the DataSet - you won't have to update your report at all, with luck the actual DataSet changes should be minimal, there is still only one DataSet call, and it's by far the simplest to maintain.
Hard code groups into the report
Here you include a table header row for each group you want to display, so these are always displayed in all cases.
Here you have some sort of conditional expression to display the values, e.g. For each group row it will be tailored to that group:
=Sum(IIf(Fields!AgeGroup.Value = "5-16", Fields!Amount.Value, Nothing)
This is not too flexible and will need updates as you change groups, and doesn't have as many options for layout. There is still only one DataSet call, so that is a plus.
Subreports
You can have a parent DataSet that displays one row for each age group, then embed a subreport in each row that displays the data you want for that row.
This allows you flexibility in layout but it will add complexity to the report(s) and will mean that you make a lot of DataSet calls that could be avoided with other options.
I know this is old, but I wanted to elaborate on Ian's section 1 above using joins at the dataset level. (His answer was super helpful to me for a report I'm working on.)
per op:
Is the solution to have a separate dataset that brings back the entire list of categories and then somehow fit them together?
That is how I've handled it successfully, but you can do so without actually creating a separate dataset by using common table expressions (or temp tables, of course).
For these example tables:
AGE_Table
ID Group Group_Desc Toys
1 A 00-10 Teddy Bear
2 B 11-20 Video Game
3 C 21-30 Sports Car
4 D 31-40 Mansion
5 E 41-50 Jewelry
People_Table (filtered for whatever date)
ID Name Age Gender Age_Group
1 Ariel 07 F A
2 Brandon 23 M C
3 Chelsea 27 F C
4 Derek 06 M A
You want to see 2 results for the 00-10 row, 2 for the 21-30 row, and then still see rows for the other age groups even if there aren't any results.
We want to create a dataset with all the different age groupings and then join on it. Behold a solution using common table expressions:
with CTE_Age AS
(SELECT Distinct Age_Group from AGE_Table)
SELECT ID, Name, Age, Gender, CTE_Age.Age_Group FROM People_Table
RIGHT JOIN CTE_Age ON
People_Table.Age_Group = CTE_Age.Age_Group
This will return:
ID Name Age Gender Age_Group
1 Ariel 7 F A
4 Derek 6 M A
NULL NULL NULL NULL B
2 Brandon 23 M C
3 Chelsea 27 F C
NULL NULL NULL NULL D
NULL NULL NULL NULL E
Once you have that in your dataset, you can change NULL values to 0 on the report builder side -- I think in 2008R2 the default is just blank.

MySQL relational database query, correct terminology?

I think my issue with databases stems from not knowing the correct terminology to help me find an answer myself so I'll explain a generic version of what I'm doing and hopefully you can point some tutorials my way or give me some terms to check into.
Let's use an example of an employee directory.
Each employee can have multiple locations, multiple job duties which pull from a separate table. Example tables & some data, let's just focus on the multiple locations.
employees
Main employee data
- id (ex: 400)
- first (ex: John)
- last (ex: Doe)
locations
Unique list of locations
- id (ex: 3000)
- title (ex: FakeCo, LLC)
map_employees_locations
Tie ANY number of locations to an employee
- id
- employee_id (ex: 400)
- location_id (ex: 3000)
I'm struggling with the logic of how a single query would return something like this:
John
Doe
FakeCo, LLC
AnotherCo, LLC
It seems I would have to run a query to get the employee data, then within a nested query, grab locations associated with the employee id, etc... If there was only one location per employee, it would be a simple join, I just don't know how to handle the multiples.
Let me know if I'm way off, I'm just struggling.
You would join all of the tables together like this
select e.id,e.first,e.last,l.id,l.title
from employees e
inner join map_employees_locations el
on el.employee_id = e.id
inner join locations l
on el.location_id = l.id
where e.first = 'John'
AND e.last = 'Doe'
This would return data like this:
e.id e.first e.last l.id l.title
------------------------------------------------
1 John Doe 1 FakeCo, LLC
1 John Doe 2 AnotherCo, LLC
If you want only one line per employee you should maybe use group concat
select id, e.last, e.first
group_concat(l.title separator ',' ) as locations
from employee e
join location l on l.employee_id = e.id
group by e.id
Not sure about the syntax cos i'm more aware of postgres but this should do the job.