MS Access alter multiple columns - ms-access

I have an ODBC linked table from JDE/AS400 that I'm bringing into MS Access 2010. The table has four fields with data types of decimal that I need to convert to double data types once I've written them to a temp table. Is there not a way to have four alter table/column statements in one query?
In case anyone is wondering, the data stored in these fields is price and cost, but they are stored in the ODBC table as decimal values of 15 with 0 trailing decimals and I have to divide two by 10,000 and one by 100,000 to get the decimal points in the right position to represent the true price/cost For example, 3558767 in the price field is actually a price of 355.8767 or 355.88 rounded). When I bring the same data into Access and divide by 10000, I get 355.00. I need the correct cents value. The only way I've been able to do this in the past is to write an alter table/alter column query to change the data type to double before performing the division.
Since I have four of these fields, I'd like to alter or modify all four at once. Any ideas?
Any help is appreciated.

There isn't a way in Access (or ANSI-compliant SQL, as far as I'm aware) to alter multiple columns at the same time; you would have to either:
run four separate alter scripts, or ...
create a new temporary table, move all the data into the temporary table, drop the main table, then rename the temporary
It's really a wash in this case, since you'll be running four scripts either way.

As mentioned, Access SQL won't allow you to alter more than one column with a single SQL statement. However, there is something confusing about the background information in your question.
SELECT decimal_field/10^4 AS my_quotient
FROM tblFoo;
decimal_field is Decimal type with precision = 15 and scale = 0.
When I store 3558767 to decimal_field and run that query, Access 2007 gives me 355.8767 as my_quotient. And that's the result I understood you want but aren't getting.
If you can sort that out perhaps you don't need to alter any column.

Related

create column names algorithmically for for large datasets in SQL

I'm looking to import a massive dataset into a mysql server. The issue is that the first 6 columns are fine to name, after that I have over 1000 columns of absorption values and I'd rather not sit there typing 'absorp-x' for hours. Is there a way to specify the first few column names when I create a table and then say "use the following format for all columns: absorp-x"?
Suggest you throw the 1000 absorption values into a JSON string and have a single column for that data. In that situation, you don't need to name the values but simply have a JSON array. (I assume they are numbered consecutively?)
That would probably fit into a TEXT CHARACTER SET ascii column. Or, if you have a newer version, a JSON column.

How can I create a table that uses an equation to average data from another table?

I have a table that contains data from repeated experiments (for example, site A has one sample, and the lab processed the sample three times obtaining slightly different values). I need to average these results in a separate table, but what I have read on the Microsoft support site is that a query that pulls data into another table with a calculated field is not possible on Access.
Can I query multiple data points from one table into a single calculated field in another table? Thank you.
UPDATE
I ended up doing a lot of manual adjustments of the file format to create a calculated field in the existing table that averages each sites data, so my problem is, for my current purposes, solved. However I would still like to understand. Following up with you both, I think the problem was that I had repeated non-unique IDs between rows when I probably should have made data columns with unique variable names so that I could query each variable name for an average.
So, instead of putting each site separately on the y axis, I formatted it by putting the sample number for each site on the x-axis:
I was able to at least create a calculated field using this second format in order to create an average value for each site.
Would have there been a way to write a query using the first method? Luckily, my data set was not at all very hefty, so I could handle a reformat manually, but if the case were with thousands of data entries, I couldn't have done that.
Also, here is the link to the site I mentioned originally https://support.office.com/en-ie/article/add-a-calculated-field-to-a-table-14a60733-2580-48c2-b402-6de54fafbde3.
Thanks all.

Working with SSRS dynamic fields

SSRS matrix table is a great way to generate dynamic fields as long as values exist.
However, is there a way to "always" show these dynamic fields even if a value doesn't exist for them? The report field locations varies based on data availability and users have to add missing columns in Excel manually.
Dynamic fields go from 3 to up to 30 (at least for now based on run by values). Adding these values manually would make the report hard to maintain.
The way I have handled for this is in the SQL. I build a table of all the values I will always want, I cross join that table to my final output table and update/insert values where they need to exist. That way I guarantee the rows, and eventually columns in the matrix, exists even if they end up being null.
Does that make sense?
Jesse's solution is a good one, but if for whatever reason you can't or prefer not to change the SQL you can do it in SSRS by forcing a blank value in the cell with a expression like this:
=iif(IsNothing(Fields!.xxx.Value)," ",Fields!.xxx.Value)

MS Lightswitch Application, add temporary fields in data table

I have a requirement to add a temporary field in a data table. There are two types of fields you can add in data table. One is DATA fields which are actual fields, and Second is COMPUTED fields which have some limitations (not discussing here).
Let me explain my scenario, I have a table with fields Qty, Rate and Amount. Now I need to add one more field like InputRate which will be just a temporary field, do not have any role in the database. Why I need this is, I need to input rate let say in US Dollar, then then I have to convert this to my own currency say SAR. So I want that this temporary field will not save in database, but the actual one (the rate converted to SAR) will be stored.
We can do this easily in .Net windows Applications or Web Applications. But how can we do this in MS Lightswitch, because it will not allow to add fields on screen untill it is part of the data table. Even if you add a custom field (as I experiment) only on the screen, then it is going to repeat the same field's value for all rows (since my this table is DETAILS table). Means if my table has 5 rows, and in 6th row if I enter anything in custom field(with scope only on screen) then it is showing the same value of all other rows also, e.g. if I entered, then all other rows start also displaying the same value 10.
Any idea how to do this?

How to create a flatfile from a series of tables in Access?

I have a series of tables in an Access 2007 database. I am trying to find a way of outputting a flat-file to an excel spreadsheet that combines all of the tables so that each row of the flatfile represents a unique combination of the table rows from each table.
For example, these tables:
Would combine to make this output table:
The challenges I'm facing are:
The 'input' tables can vary in number of rows and columns, as well as quantity
The total number of rows in the final output table can get quite large (200,000+ rows)
I know Excel and VBA (in Excel) well but almost nothing about Access
Is there a way to do this in Access? Is there some native functionality in Access that I'm completely overlooking? Any pointers (even if it's "you need to read into X and Y") would be greatly appreciated!
Thanks,
Adam
As noted above:
Create a new query. Select your 3 tables as the data sources. If desired, set up joins between tables by dragging a line between a field in one table to a field in another. Without joins you will get a Cartesian Product ... every from 1st table paired with every row of 2nd table, and then each of those combination paired with every row of 3rd table. Select the fields you want included in the result set. When the query returns what you need, save it and give it a name. Then you can export that named query to Excel.
If the table is large, you could hit Excel's row / column limit though.