SSIS - do not allow if - sql-server

I have an employee table with both Active and Terminated employees, one of my columns is work email. Terminated employees should have their personal emails listed and Active employees should have their work emails listed. However, the source system I am pulling the information from allows active employees to update their work email. So I have some active employees with their personal emails listed.
For my purposes, I need all active employees to have their work email listed. In SSIS, what would be the best approach to solving my issue?
Ex:
Name Status Email
Bob Act bob#workdomain.com
Joey Ter joey234#yahoo.com
Randy Act randy23#hotmail.com
Here, since Randy is as Active employee should have an email ending with #workdomain.com but, in the source system I pulled data from Randy changed his email to be his personal. Randy's email should be: randy#workdomain.com

I would have done like below (to avoid OLEDB transformation - row by row operation).
Load the data to 2 Staging tables (may be temporary tables):
Table#1. StageEmp:
Name Status Email
Bob Act bob#workdomain.com
Joey Ter joey234#yahoo.com
Randy Act randy23#hotmail.com
Table#2: CorrectEmail
Name Email
Randy randy23#hotmail.com
In Execute SQL Task:
Update s
SET s.email = c.email
FROM StageEmp s
Join CorrectEmail c
ON s.Name = c.Name
where s.status = 'Act'
AND s.email not like '%#workdomain.com'
You should use key column in place of Name.
Load the data of StageEmp to actual table or update directly to the actual table.

According to me, you have one Data Flow Task under which you have one Excel Source to fetch data from excel file. You can do this way -
1. Add one "Lookup" component and pass output of "Excel source" to it.
2. Edit "Lookup" component, and add second source of input to it from your existing table (where you have work email).
3. Join these two inputs to "Lookup" component on the basis of one of the key columns,
so that in output you have two columns one email column from source and one email column from destination.
3. Add "Derived column" component and pass output of "Lookup" to it.
4. Edit "Derived Column", add new column and add expression to check whether email column has "#work-domain" or not.
If yes, then source email else destination email.
Hope so i am able to explain.

Related

MS Access: Auto-populate form fields based on multiple tables

I have the following 3 tables:
Retailers - ID, Name
Registration - ID, Status (YES/NO)
Refund - ID (populated into a dropdown list from Retailers table), Name (Empty), Status (Empty)
Retailers is a table full of data, while Refund starts off as an empty table that gets filled in as a Refund Form is filled up. After creating a form based on the Refund table, how do I allow a user to select an ID from the dropdown list and populate the corresponding Name into the Name field and Status into the Status field?
What are the queries needed and how do I integrate this into the form?
I have tried the method found here - https://www.linkedin.com/pulse/autofill-form-microsoft-access-tim-miles
However, I have run into 2 problems:
1) The form does not appear in "Form View"; it is only viewable in layout view. I have read many links saying that the queries are read-only or that there are no records in the first place etc. The answers don't make sense.
2) If I bind the form (instead of a table) to a query this way, how do I save this new data into another table? My intention was to have the record saved in Refund table.
Sounds like Refund is your base table here. So, the query you want is:
SELECT a.[ID], b.[Name], c.[Status]
FROM Refund as a
Left Join Retailers as b
ON a.[ID] = b.[ID}
Left Join Registration as c
ON a.[ID] = c.[ID]
You'll need to make all 3 ID fields the Primary Keys in their respective tables. This should make the query updateable, and then you can use this query as the DatSource for your form.
You also have to make sure you set up the Relationships for all the tables. If you've never done it, it's easy to do and Microsoft gives you instructions here:
https://support.office.com/en-us/article/Create-a-relationship-40c998dd-4875-4da4-98c8-8ac8f109b85b
By setting up referential integrity in the relationships, you can save the data.

MS Access form to update multiple tables without subforms

I am quite new to creating dbs in Access but I am not a fan of subforms, I can already tell that much, they are nice for one to many relationships (one customer, many orders) but when I just want to reduce redundancy and create a one to one relationship between tables and I only at all times would need one record from another table, subforms no longer feel so nice.
My example:
I have 2 tables, 1 for companies (ID, company name, country ID) and one for countries (country ID, name of the country). To eliminate repetition of country names I use country ID to link the 2 tables, and only add the ID of the country, not its name.
When I create a form for the "companies" table I want one field that says where that company is located instead of a subform (because I still havent figured out how to hide the box around it), so practically having one field that's connected to a different table.
And then through the one to one connection, when a record is selected the form would show in one field where the company is located. Is this possible?
Extra: I have 2 countries in my "country" table, the UK and Germany, but a new company I am adding a record from this form, is located in France, is it possible that I just enter France into the field and it automatically creates a new record in the "country" table for France, and also adds the new record's ID to the "company" table, to the company that's located in France
It seems your form and subform are based directly on tables. Try basing your main form on a query:
SELECT
company.ID,
company.CompanyName,
company.CountryID,
country.CountryName
FROM
company
INNER JOIN country ON
company.CountryID = country.CountryID
This will eliminate the need for a subform.
Extra: You may actually want to have the 'country creation' function on a separate form, or invoked from a button push on this main form.
Having Country IDs to force users to pick a standard country from a list is a very good idea. However if you also let them arbitrarily enter new ones in the same box you're trying to prevent them from mistyping in, that good work can come undone.
Yes this is absolutely possible. The way I do this is with unbound forms, so I control all of the SQL statements to tell the data what to do and where to go.
Since you have 3 fields being sent into a row in the "companies" table and 2 fields being sent into a row in the countries table with 1 of the fields being in a relationship (I'm assuming 1 to many), create 4 textboxes (or whatever other control) on your form. The controls will be for: ID (assuming this is inputted by the user and not an autonumber. If it is, please comment below), company name, country ID, name of country. When you fill all of them out, have a button with a Click event. In here you will have 2 SQL statements to insert records, 1 for each table.
The code will look like this:
Private Sub button_Click()
DoCmd.RunSQL "INSERT INTO companies VALUES ([ID].Value, [company name].Value, [country ID].Value)"
' The words in the [] are the names of your controls on the form
DoCmd.RunSQL "INSERT INTO country VALUES ([country ID].value, [country name].value)"
End Sub

MS Access default value from another table

I have two tables in a database. One is called salesreceipt and the other is salesreceiptlinedetail.
Each row in salesreceiptlinedetail has a field IDKEY that matches a field TxnID in a row in salesreceipt. There can be multiple rows in salesreceiptlinedetail that can match the same row in salesreceipt.
I have third party software that syncs my access database with Salesforce. The software only allows querying one table in the database at a time.
I need to automatically copy some of the fields from the salesreceipt table to new fields in the salesreceiptlinedetail table so I can sync the data correctly.
I'm very new to MS access. After trying many different things I landed on a solution that I think may work but I'm not sure how to do it. It looks like I can set the default value of a field. I'm thinking I need to do a DLookup to find the field I want to copy in the salesreceipt table and somehow use criteria to check the IDKEY matches the TxnID. I think I need to create a module with a function to do this but I'm not sure how and how to call it.
I may be way off on this. I could use some help or ideas. I've been researching for hours and could use a little push in the right direction. Thanks in advance.
Here's some things you can try, though I'm making some assumptions about the tables you've got and the result you're looking for.
So you've got a table called salesreceipt with an ID field TxnID and some other data (e.g. CustomerRef_FullName):
And then you've got a salesreceiptlinedetail table that has a field IDKEY field that matches back to salesreceipt table's TxnID field (i.e. a foreign key) and an empty field (e.g. FullName) that you want data for by matching the record back to the salesreceipt table.
I can think of a few ways of achieving this so that you end up with a table that has the information you want, but I'm not sure which is best for you. All these options shown are using Access 2013.
1) Get the data using a SELECT query and export those results across to your third-party software:
In Access, go to Create / Query Design:
Add your salesreceipt and salesreceiptlinedetail tables to your query and then close the Show Table window:
Click and drag on the TxnID field to the IDKEY field to create a join (represented by a line in Access):
Double-click on the IDKEY from your salesreceiptlinedetail and CustomerRef_FullName from your salesreceipt table; they should show as fields in the area at the bottom (if you have other fields you need then add those too, I'm just going on 1 field for illustrative purposes):
Click run to see the result of this query:
Hopefully this is showing a table that's starting to fill-in the blanks you want:
You can then save the query (right-click on the query table and chose "save" and name it whatever you want):
And export the results to a spreadsheet (assuming spreadsheet is the format your third-party software takes). Go to External Data / and then click "Excel" from the export group:
The query with the name you saved it as will be there in the Access Objects side-bar so that you can run it and export the results again (double-click on it to run it again):
The good thing about this method is that it's faster than using DLOOKUPs (these can be resource-heavy if you have a lot of records) and if there is new data/records in your salesreceipt and salesreceiptlinedetail tables, the query will run on that new data and include it in its results without you having to modify the query.
For your question though, it sounded like you might want to populate your salesreceiptlinedetail table with the data you need... this SELECT query will not do that. If you want to populate the actual salesreceiptlinedetail table you will need an UPDATE query...
2) Populate empty fields in salesreceiptlinedetail using an UPDATE query matched to records from salesreceipt
In this example, we're going to populate an empty field in salesreceiptlinedetail, namely the FullName field. We're going to do this by matching records in salesreceiptlinedetail to salesreceipt using the IDKEY and TxnID fields and then bring across the corresponding data in the CustomerRef_FullName field to the FullName field.
To do this, setup a new query the same way we did in (1) above and stop after you complete this stage:
Change the Query Type to an "Update" query:
Double-click the empty field you want to populate, e.g. FullName from the salesreceiptlinedetail table:
In the "Update To" box, type the name of the corresponding table and field you want to use to populate your empty field. Enclose the table and field each by a pair of square brackets and separate each by dot. So it should look something like this:
[salesreceipt].[CustomerRef_FullName]
In the criteria box, match your IDKEY and TxnID fields, like this:
[salesreceiptlinedetail].[IDKEY]=[salesreceipt].[TxnID]
Click "Run" and Access should show a warning that it is about to update some records in a table. Click Yes to allow it to do this:
If you go back to your salesreceiptlinedetail table, you should see that the once empty FullName field is now populated:
You can then save your UPDATE query for use again later - be aware that double-clicking on the query will open it AND run the UPDATE again (i.e. it will attempt to populate your salesreceiptlinedetail table with new data), so if you don't want that to happen you can right-click on it and open it Design View before opting to run it.
This method is good if you want to populate data in an already existing table, rather than essentially building a new table of results out of existing tables as described in (1) when we used a SELECT query.
If there's new data in salesreceiptlinedetail or salesreceipt, you'll want to run this UPDATE query again.
This is to add to Matt's answer. We have similar situations for a miniature reporting database, where we need to update the database several times through out the day. We wrap the query in a function and schedule a task in Windows to run every 4 hours that executes the Access function and updates the data.

How to populate a text item from Oracle table using Oracle forms (Middleware) 11gR2

I am using Oracle with Oracle Forms builder (Middleware) both 11gR2. I am creating a system for purchasing records. I have the following 2 tables.
(a) product (master) : prodid(PK), prodname ...... etc.
(b) purchase (detail) : prodid(FK), quantity, ...... etc.
My plan: All the product details will be in the product table. purchase table will be used only to input purchase information. This table can't input any new product. If any new name, that info will have to be input into product table first. This way I can reduce duplicate names.
Now I am having difficulties relating to prodname (name of the product) column in the form.
I created forms using the purchase table only. This table does not have the prodname (because I put this field in product table) column. But during data entry, they need to see the product name !
So I created text item (tabular, database - no). Then I created LOV, attached to text item, input the prodid in prodid field in the form. LOV part is fine.
I run the form. click the text item, LOV appears, select a name, click OK. product name, product id, etc. appears in their fields as it should be. LOV is working fine. Now I can only input data but having difficulties updating. I mean if I input a name (LOV) in the text item, press execute query, shows records from the database but names in the text item disappear. Since the name is not here, it's not comfortable to update.
I think LOV is not the good idea here. May be I need to use PL/SQL in a trigger somewhere.
But I could not figure it out. I searched google but no luck. Is there anyone who can give me any idea or some example code/trigger please.
Since the product name is an non-database item, when execute query runs, the field is cleared and since no column is assigned to that field, it doesn't repopulate.
The usual way to populate this field is to have a function which returns the product name based on the id that is pressed and call the funtion in POST-QUERY trigger.
Basically it's a pretty simple task but I was having difficulties due to the lack of my experience. However, what I have done is -
create the text item (name : product_name) in the canvas
set properties for the product_name (database : No, .... etc as needed).
Create a block level POST-QUERY trigger and write the PL/SQL block to populate the field. For example, I wrote the following.
BEGIN
SELECT prodname INTO :purchase.product_name
FROM product WHERE product.prodid = :purchase.prodid ;
END ;
That's it and when perform execute_query in the form, it will bring the product name from another table. - Query problem is solved.
Now create an LOV using product table to bring the product name and product id.
Associate this LOV to the product_name text item. So whenever you need to input information about a purchase, just use the LOV to populate the product name field. And then input the subsequent fields as well.
This way both of my issues (query and data entry) are resolved.
I did this according to the suggestions given by Sathya and a video (6 minutes) from the youtube at https://www.youtube.com/watch?v=0nqldnGt8KA.
Thanks to Sathya and youtube.

Database Tables - To decouple or not?

Is it better to create tables that store a lot of data that are related to an entity (User for example) or many tables to store said data?
For example:
User Table
Name
Email
Subscription Id
Email Notifications
Permissions
Or
User Table
Name
Email
Subscription Table
User ID
Subscription ID
Notification Table
User ID
Receives?
... etc
Please consider code in this as well, or I would have posted to ServerVault.
From a relational design standpoint what is important is the normal form you're aiming for. In general, if the "column" would require multiple values (subscription_id1, subscription_id2, etc) then it is a repeating group, and that would indicate to you that it needs to be moved to a related table. You've provided very general table and column notes, but taking a cue from the fact that you named "Email Notifications" and "Permissions" with plurals, I'm going to assume that those require related tables.

Resources