Two way connection between excel and access - sql

My requirement is there are multiple copies of same excel sheet with multiple users who update a table in the excel sheet.Then there is an access database where one of the tables get updated from the excel table updated by multiple users and also the change done by any one of the users in their excel sheet should also reflect in all the other users excel sheet. The users don't have access to the access database. I am working in 2007 version.
What I need to do is
1.connect all the excel copies to the access database.So if there's any change done by any of the user it gets updated in the access database.
2.Now the change that has been done by one of the user in the excel sheet should also reflect in the excel sheet of all the other users.
I tried solving this by linking the excel files to the access database which created many linked tables in access. So, this way the change in one of the excel file was reflecting in its respective linked table created in access.Then I joined all the linked tables to one table(say joined table) by using union query. Then I connected this joined table to the multiple excel sheet.When the user opens or refreshes the excel sheet, the table in the excel sheet gets updated.
But the problem that I am facing now is when there's some change done in one of the records in excel file instead of overwriting that record in the joined table it creating another record.So, now there are two records one record without the updated data and another with the updated data in the joined table and these two records are reflecting back in the table excel sheet as well. So say if I have 50 records in each of the linked file then there are 51 records getting created in the joined table in access database as well as in the excel table.
Can you please help me solve this as I have tried lot but I am unable to solve this.

Related

Looking to have a copy of another database that automatically updates and has a few additional columns

I'm very new to database/server management. I'm working with a database that I can't add any columns to since it interfaces directly with another piece of software and therefore must stay in a very specific format. However, I'd like to be able to add DateCreated, and CreatedBy columns to the tables in this database to setup some automatic email updates when new entries are made. To do this, I thought I might be able to keep a copy of the original database that automatically updates when changes are made to the original and simply add the additional columns to the copy. I'm working in Microsoft SQL 2017. If anyone could provide any guidance on the best way to accomplish this, your help would be much appreciated.
Create a table extension that consists of the additional columns + the key value from the original table. Each row in Table 1 should have 1 or 0 rows in Table 2. Use a trigger on Table 1 to insert a row in Table 2 on Insert or Update.

How to entry more than one value for a feature in sql

I have a project that is a clinical web based system, I need to save some sheet data in SQL database.
I have "TumorSite" table, by this table I show checkboxes that user can select one or more of them in MVC 5.
I also have "PathologyReport" table, I wanna to save all of the data about pathological data of a patient into it.
Some fields in "PathologyReport" should be complete from checkboxes that checked, some not and fill from textboxes. For checkboxes, if the user checks "other" another value should b saved.
How to fill multiple checkbox values for a patient? Do I need another table?
How to link "PathologyReport" to the new table?
What should I write in the controller in mvc?
please see my form.
Yes, you usually need another table for that. Some SQL databases allow an "array" data type for columns (e.g. Oracle), but the usual approach is another table with a foreign key.

How to implement an add if not available in the database in Pentaho?

How do I implement, or what steps do I use to create a transformation that compares a table and a list . For example a database table name Schools and an excel file with a huge list of names of Schools.
if the entry in the excel is not seen in the database, it should then be added to the database table.
I'm not quite sure if I can use the database lookup step, it does not tell if a lookup fails. insert update step doesn't seem a solution as well, for it requires some ID value but no ID is present on the list of schools in the excel file
Based on the information that you provided a simple join with table insert step will do your task. You can use the Merge rows step for comparing both the data stream (excel and database). The merge rows step uses the key to compare two streams and add a flag field which marks the row as new, identical, changed, deleted. In your case you would like to insert all the rows that are marked as new by using table insert step.
Please check the below links for more reference.
Merge rows, Synchronize after merge
This what worked for me,
excel file -->
select values (to delete unnecessary fields) -->
database lookup (this will create a new field, and will set null if not found) -->
filter rows (get the fields with null output from lookup) -->
table output (insert the filtered records)

Count Customers in a column

I have a table that has 1K rows. In the table there is a column that has the names of the customers. I need to add a column that counts (index) how many customers I have.
Doing a calculated measure using the distinctcount formula I get 3156 customers. My goal is to accomplish the same result of the calculated field in a calculated column.
Thanks for the help.
Not sure about a calculated column but one way you can accomplish this is to make related dCustomers dimension table from your source. You question didn't happen to mention your source - here is how I'd do it for the most common sources in my estimation:
SQL database connection:
SELECT DISTINCT customerField
FROM yourViewOrTable
Excel/Text File:
Duplicate the worksheet with the Linked Table.
On the worksheet copy delete all columns except the Customers column.
With the a single cell active in the data go to Data>Remove Duplicates.
Under the PowerPivot ribbon tab click Create Linked Table.
Now What?
You should now have two tables from whatever source you are using. You'll find your new table has 3156 records in it. Go to Diagram view and drag a relationship from table1.CustomerField to table2.CustomerField.
With the relationship made you should be able to do anything you need to do, but please fire back if you have any questions on your use case.

How to create query to update records only when changes occur and to add new records that do not already exist

I am running a query that fetches data(records) form a linked table from another database.
The linked table is populated by users using a form remotely, like the web.
I created this piece of code that queries the data from the linked table into a new table, like this:
`INSERT INTO NEW_TBL(ENT_CUS_NUM, ENT_FIRST_NAME, ENT_LAST_NAME, ENT_ADDRESS1, ENT_CITY, ENT_STATE, ENT_ZIP, ENT_PHONE)
SELECT LINK_TBL.CUS_NUM, LINK_TBL.FIRST_NAME, LINK_TBL.LAST_NAME, LINK_TBL.ADDRESS1, LINK_TBL.CITY, LINK_TBL.STATE, LINK_TBL.ZIP, LINK_TBL.PHONE
FROM LINK_TBL`
Is it possible to modify this query so that it inserts new records from the link table if the record has not already been added, or update existent records
that have been modified? Example: Lets say a person changes their address, Can I update or bring over only their address without re-inserting their entire record because of an address change?
This is what confuses, I could write an update statement but modifying this querying so that it brings over new records or update records with changes is way over my head.
I would appreciate your input and help.
Guy
If you can designate a field as a unique key, you can use REPLACE INTO instead of INSERT INTO at least with mysql