Access 2010: data rows as column headings? - sql

I'm using MS Access 2013.
I need to display AND EDIT a grid of data based on three tables:
UnitID UnitName
1 Unit1
2 Unit2
3 Unit3
ProdID ProdName
1 Furniture
2 Food
3 Other
UnitID ProdID Forecast
1 1 10
1 2 20
1 3 30
2 1 40
2 2 50
2 3 60
3 1 70
3 2 80
3 3 90
so it looks like:
Unit1 Unit2 Unit3
Furniture 10 40 70
Food 20 50 80
Other 30 60 90
Furthermore, the query must be editable (user should be able to enter his forecast data).
Any idea how to do this in Access 2010? I've looked into pivots and crosstab queries, but they use aggregate functions and thus aren't editable... but in my case, the source of the data is unambiguous so an editable option should exist? Anyone has an idea how to get the data in editable format?
Thanks!
Jur.

Create a temp table and fill it with the data from your crosstab query. Use that table as the source for a form, which will be editable. In the beforeupdate event of the form, add code to update the original source table.

Thanks all,
distributing any kind of exe is not an option due to security measurements in the client's environment (they can run Office and little else). So I'm going for the temp table option anyway... any pointers for a template solution to modify to my needs?
Thanks again!
Jur.

Related

How to merge two Spreadsheets into one in google spreadsheets

There are two Spreadsheets namely main and secondary. Main has 3 sheets in it and Secondary has 1 sheet under it. For simplicity I'll show modified version of them both under
Main spreadsheet
Name Qrating Brating Crating
A 8 5 4
B 5 2 1
C 6 7 9
Secondary spreadsheet includes personal details of same people present in Main spreadsheet as seen below.
Name Age Rank qualified
A 23 2 yes
B 45 22 yes
C 44 23 yes
I have looked up ways to merge and combine but all seem to be ways in combining data vertically, but what i want is all the data in secondary to be added in Main file in accordance to the name. I don't seem to find the solution online where data is filled horizontally after tallying a common column between two files. if anyone can give solution or guide me to a direction that would be very helpful. Thankyou.
end result should be like this when merged
Name Qrating Brating Crating
A 8 5 4
B 5 2 1
C 6 7 9
Name Age Rank qualified
A 23 2 yes
B 45 22 yes
C 44 23 yes
Name Age Rank qualified Qrating Brating Crating
A 23 2 yes 8 5 4
B 45 22 yes 5 2 1
C 44 23 yes 6 7 9
It is very easy to do this with click on feature in Microsoft Excel, I was expecting the same in Google sheet but it seems the add-ons help for this as I didn't find any tool in sheets itself. There are many add-ons to achieve this, I am using Merge Sheets add on for this.
You can merge multiple sheets form different spreadsheets like this
=query({
IMPORTRANGE("ID_1"; "SheetX!A2:E");
IMPORTRANGE("ID_2"; "SheetX!A2:E");
IMPORTRANGE("ID_3"; "SheetX!A2:E")
};"SELECT * WHERE Col1 IS NOT NULL")
and then adapt query as you need. Wait for an example from your side. Sincerely yours.

MS Access average a value based on other column data

So my data looks something like this:
Smpl_id Plate_id CT_Value
1 1 27
1 1 32
2 1 56
2 1 49
1 2 40
1 2 36
2 2 58
2 2 64
I would like to design a query that returns averages of CT_Value of each sample in a plate, so it would look like this:
Smpl_id Plate_id Avg_CT
1 1 29.5
2 1 52.5
1 2 38
2 2 61
I have tried
Avg_CT: DAvg("[CT_Value]","[qPCR_sample_data]","[Plate_id] = '" & [Plate_id] & "'" And "[Smpl_is] = '" & [Smpl_id] & "'")
But that just results in:
Smpl_id Plate_id CT_Value
1 1 45.25
1 1 45.25
2 1 45.25
2 1 45.25
1 2 45.25
1 2 45.25
2 2 45.25
2 2 45.25
I can't just list the plate or sample id numbers because this is actually a long list that is continually growing. I also need to use these average numbers in future calculations (that I have already figured out how to do).
Also, I have just started using MS Access (designing a brand new database), so I kinda understand SQL but have very little actual experience in it.
Thank you!
You will need to use a group by query.
Create a new query, and add the table (in my example I've called it tblSample).
Add the three fields, Smpl_id, Plate_id and CT_Value to the query grid.
On the Query Design memubar, click on the button labelled "Totals".
This introduces a new row in the query grid called "Total", with all three fields having it set to "Group By".
Simply change the "Group By" for CT_Value to "Avg", and run the query to get the results you are after:
Regards,
You should be able to use simple aggregation such as:
select t.smpl_id, t.plate_id, avg(t.ct_value) as avg_ct
from qpcr_sample_data t
group by t.smpl_id, t.plate_id

Using sequences for every row in a sql-server table

We have a table Property in our database containing a counter in every row stored in the NextVoucherNumber integer column. There are about 2000 rows there.
ID ... {other columns} ... NextVoucherNumber
-----------------------------------------------
1 112
2 34
3 29
4 9456
.... ....
2000 233
We have an issue with a concurrent access to the table.
To improve the performance we would like to extract those columns to a separate table PropertyVoucherNumbers with a 1:1 relation between the rows.
ID NextVoucherNumber
------------------------
1 112
2 34
3 29
4 9456
.... ....
2000 233
Alternatively, we could maintain sequences for every row.
Seq_VoucherNumber_1, Seq_VoucherNumber_2, ... Seq_VoucherNumber_2000.
Looks like the same triggers just a little dynamic SQL there.
Could you please describe what the problems we will face using the second solution?
Can you suggest any better solution?

Table Manipulation in DB2

I am using DB2 and have the following table (Table A - 3 Columns) :
EmpNum YearMonth Value
100 201201 2
100 201207 1
100 201206 7
102 201201 8
102 201205 15
102 201207 4
… etc
I would like to produce a new Table B with one row per employee, and a column for each YearMonth.
I am hoping that I can generate the Table B 'YearMonth' column name dynamically from the data as there will be 120 columns.
The value would then be put in the cell with the associated YearMonth heading to give a table like this :
EmpNum 201201 201202 201203 201204 201205 201206 201207 etc ….
100 2 7 1
102 8 15 4
I have tried looking up 'Stored Procedures' and 'Dynamic Column Names' but cannot fine anything quite like this.
I have two questions :
Is this possible in DB2 ?
What should I look up for more information ?
Thanks in anticipation !
Ross
What you are looking for is called Pivot. Unfortunately, DB2 doesn't implement the PIVOT statement (unlike Oracle). So it will not be possible to create a query that creates a dynamic number of columns.
Have a look at Poor Man's SQL Pivot. List Questions as Columns and Answers per User in one row. That's the closest you can get to.
This is a generic procedure that allows to pivot a table: https://github.com/angoca/db2tools/blob/master/pivot.sql

MS Access CrossTab query - across 3 tables

I have the following 3 tables:
1) Sweetness Table
FruitIndex CountryIndex Sweetness
1 1 10
1 2 20
1 3 400
2 1 50
2 2 123
2 3 1
3 1 49
3 2 40
3 3 2
2) Fruit Name Table
FruitIndex FruitName
1 Apple
2 Orange
3 Peaches
3) Country Name Table
CountryIndex CountryName
1 UnitedStates
2 Canada
3 Mexico
I'm trying to perform a CrossTab SQL query to end up with:
Fruit\Country UnitedStates Canada Mexico
Apple 10 20 400
Orange 50 123 1
Peaches 49 40 2
The challenging part is to label the rows/columns with the relevant names from the Name tables.
I can use MS Access to design 2 queries,
create the joins the fruit/country names table with the Sweetness table
perform crosstab query
However I'm having trouble doing this in a single query. I've attempted nesting the 1st query's SQL into the 2nd, but it doesn't seem to work.
Unfortunately, my solution needs to be be wholly SQL, as it is an embedded SQL query (cannot rely on query designer in MS Access, etc.).
Any help greatly appreciated.
Prembo.
How about:
TRANSFORM First(Sweetness.Sweetness) AS FirstOfSweetness
SELECT Fruit.FruitName
FROM (Sweetness
INNER JOIN Fruit
ON Sweetness.FruitIndex = Fruit.FruitIndex)
INNER JOIN Country
ON Sweetness.CountryIndex = Country.CountryIndex
GROUP BY Fruit.FruitName
PIVOT Country.CountryName;
I hate to rely on an outside post and present it as my answer, but this is a pretty steep topic and I can't do it justice. So I suggest you look at this article.