error handling ininformatica using error and abort - duplicates

I am new to informartica.Could you please help me with this requirement.
I have a list of columns with 2 categories .
Hard check: if the column is null then that record should not flow to the target and should be logged in the error table (not informatica inbuild relational one,I am planning to create separate error table using normalizer)
Soft check: if the column is null then the record should go to exception as well as target table
I also want a duplicate check in the error table, I want the column name in a column called description.
I am aware of using ERROR function in expression to check for not null.But
I also want to capture records with duplicates and display the null records.
Example:
record 1 has abc,wer column as null (soft check column)
record 5 has def column as null ( hard check column)
Error table example:
date id reason description
-----------------------------------------------
1/2/2014 10 duplicate record duplicate
1/3/2014 1 null abc,wer
1/4/2014 5 null def
Sorry for not being clear while explaining the requirement.I have handled the duplicate scenario in a different mapping.
Below is the requirement for Hard/Soft Checks:
Hard Check: Record should not flow to the target table(only to exception table)
Soft Check :Record should flow to the target table as well as exception table
Hard Check columns : Tarnsid
Soft Chech Column : Date Date2
Source table
Position_id trans_id Date Date2
1 abc123 31-dec 31-dec
2 abc1234 31-dec 31-dec
3 abc12345 31-dec 31-dec
4 31-dec 31-dec
5 abc 123456
6 abc 1234567
Target Table
Position_id trans_id Date1 Date2
1 abc123 31-dec 31-dec
2 abc1234 31-dec 31-dec
3 abc12345 31-dec 31-dec
5 abc 123456
EXCEPTION TABLE
Position_id description table_name Column_Name Check
4 transid is null Source table transid Hardcheck
5 Date,Date2 is null Source table Date,Date2 SoftCheck
6 Date is null Source table Date,Date2 SoftCheck
While loading into the target table am checking whether the check=Hardcheck in
expection table then it will not flow to the target.
Could you please help me with the logic of populating the exception table.

In Expression transformation, you can do something like this:
o_check:= IIF(ISNULL(trans_id),'Hardcheck',IIF(ISNULL(date1) OR ISNULL(date2),'Softcheck','No Error'))
v_col_nm:= IIF(ISNULL(trans_id),'transid','')
||IIF(ISNULL(date1),',date1','')
||IIF(ISNULL(date2),',date2','')
o_col_nm:= v_col_nm
o_description:= v_col_nm||' is null'
This will create your output columns for Exception table. Now you can put a router with two groups for Target and Exception tables respectively, and the group conditions should be like below:
For Target: IN(o_check, 'No Error', 'Softcheck')
For Exception: o_check != 'No Error'
Connect appropriate columns to target and exception tables.

Related

FInd missing row based on Column data -MySQL

I am currently working on a.Net web form solution which generates a brief service report for admins to monitor the services done by technicians.As of now , i am having some trouble in coming up with an efficient SQL (for MySQl) which return data rows along with the missing rows based on the SertvicePrtNum , which is in order.
For Example :-
This is my raw data in the table :-
Id ServiceRptNum Customer_ID Date of Service
---- ------------- ----------- ---------------
1 1001 3 09/10/1997
2 1003 8 10/06/2005
3 1005 1 21/02/2003
4 1007 7 1/06/2011
5 1010 4 4/11/2012
6 1002 2 16/01/2003
Here the ServiceRptNum , 1004 is missing in the table. So i want the db to return the result as : -
Id ServiceRptNum Customer_ID Date of Service
---- ------------- ----------- ---------------
1 1001 3 09/10/1997
2 1002 2 16/01/2003
3 1003 8 10/06/2005
- 1004 - -
4 1005 1 21/02/2003
- 1006 - -
5 1007 7 1/06/2011
- 1008 - -
- 1009 - -
6 1010 4 4/11/2012
Here , the sql additionally generated 1004,1006,1008,1009 since it cannot find those records.
Please note that the Id is automatically generated (auto_increment)while insert of the data.But the Service ReportNum is not , this is to enable the admin to add the service report later on with the manually generated report Num (report num in the hardcopy of the company Servicebook).
You basically need to invent a constant, sequential stream of numbers and then left join your real data to them. For this method to work, you need a table with enough rows in it to generate a counter big enough:
select ID, 1000+n as servicerptnum, customer_id, `Date of Service` from
(
SELECT #curRow := #curRow + 1 AS n
FROM somebigtable
JOIN (SELECT #curRow := 0) r
WHERE #curRow<100
) numbergen
LEFT JOIN
tablewithmissingservicerptnum
ON
servicerptnum = 1000+n
You need to alter some things in the code above because you never told us the name of your table with missing rptnums. You also need to utilise another table in your database with more rows than this table because the way this method works is to count the rows in the bigger table, giving each a number. If you don't have any table bigger than this one, we can probably get enough rows by cross joining a smaller table to itself or by using this table. Replace somebigtable with thistable CROSS JOIN thistable where this table is the name of the table with missing servicerptnums
If you want just the rows that are missing, add a WHERE servicerptnum is null to the end of the sql
Edit, I see you've changed your numbering from:
1001
1002
...
1009
10010
To:
1009
1010
The join condition used to be servicerptnum = concat('100', cast(n as varchar)), it is now servicerptnum = 1000+n..
Look here for ideas on how to generate a group of continuous integers, then select from that left outer join your table. You should get a row for every number but all the values will be null for the missing numbers.

T-SQL query procedure-insert

I am wondering if any of you would be able to help me. I am trying to loop through table 1 (which has duplicate values of the plant codes) and based on the unique plant codes, create a new record for the two other tables. For each unique Plant code I want to create a new row in the other two tables and regarding the non unique PtypeID I link any one of the PTypeID's for all inserts it doesnt matter which I choose and for the rest of the fields like name etc. I would like to set those myself, I am just stuck on the logic of how to insert based on looping through a certain table and adding to another. So here is the data:
Table 1
PlantCode PlantID PTypeID
MEX 1 10
USA 2 11
USA 2 12
AUS 3 13
CHL 4 14
Table 2
PTypeID PtypeName PRID
123 Supplier 1
23 General 2
45 Customer 3
90 Broker 4
90 Broker 5
Table 3
PCreatedDate PRID PRName
2005-03-21 14:44:27.157 1 Classification
2005-03-29 00:00:00.000 2 Follow Up
2005-04-13 09:27:17.720 3 Step 1
2005-04-13 10:31:37.680 4 Step 2
2005-04-13 10:32:17.663 5 General Process
Any help at all would be greatly appreciated
I'm unclear on what relationship there is between Table 1 and either of the other two, so this is going to be a bit general.
First, there are two options and both require a select statement to get the unique values of PlantCode out of table1, along with one of the PTypeId's associated with it, so let's do that:
select PlantCode, min(PTypeId)
from table1
group by PlantCode;
This gets the lowest valued PTypeId associated with the PlantCode. You could use max(PTypeId) instead which gets the highest value if you wanted: for 'USA' min will give you 11 and max will give you 12.
Having selected that data you can either write some code (C#, C++, java, whatever) to read through the results row by row and insert new data into table2 and table3. I'm not going to show that, but I'll show how the do it using pure SQL.
insert into table2 (PTypeId, PTypeName, PRID)
select PTypeId, 'YourChoiceOfName', 24 -- set PRID to 24 for all
from
(
select PlantCode, min(PTypeId) as PTypeId
from table1
group by PlantCode
) x;
and follow that with a similar insert.... select... for table3.
Hope that helps.

Is it possible, and if so how, to "link" two MySQL database columns together inside two different tables?

I have one database that has a bunch of tables in it. 8 of these tables have field named 'status' which gives the effective status notification of the data within that row.
I have another table which is acting like an index to the earlier mentioned 8, and this also has a matching "status" col. Currently if the status col changes in one of the 8 data collection tables, I need to make the php also update the relevant index tables status col to match. It would be much nicer and less error prone to coding oversight, if I had a way inside MySQL to link the index tables 'status' field to the matching 'status' field in which ever of the eight tables the core data resides in. It'll always only be one of the eight, depending on the form type selected. Is such a thing possible?
Data added as per request. First is a sample of what I call the "index" table. Any data placed into one of the other 8 mentioned tabled, will also have an entry into this table.
id appNo applicationKey applicationName uID status
1 3 AIGs2GRA A.I.G stage 2 Grant App 1 Data Acquisition
2 2 AIGs1PIA A.I.G stage 1 Process App 1 Data Acquisition
3 3 AIGs2GRA A.I.G stage 2 Grant App 1 Declined
4 2 AIGs1PIA A.I.G stage 1 Process App 1 Data Acquisition
5 3 AIGs2GRA A.I.G stage 2 Grant App 1 Data Acquisition
6 3 AIGs2GRA A.I.G stage 2 Grant App 1 Pending Review
7 8 VisFelAp Visiting Fellowship App 1 Data Acquisition
8 3 AIGs2GRA A.I.G stage 2 Grant App 1 Data Acquisition
9 8 VisFelAp Visiting Fellowship App 1 Accepted
The id is auto incremental. appNo and applicationKey are used to identify what type of App is being entered. applicationName is obvious, uID is the id of the user who entered the application - myself in all these cases so they're all "1" right now. The last col, 'status' is what I am wanting to be "linked" to the relevant matching column in whichever other table the data resides within. This is indicated by the applicationKey - for example the data for the first entry here will be stored within the table named 'app_AIGs2GRA' whereas the data for the last (id 9) entry will reside within the table 'app_VisFelApp'.
All of the data tables start the same way, like this:
appID uID uaID status
1 1 2 Data Acquisition
2 1 4 Data Acquisition
This sample is taken from the app_AIGs1PIA table, you'll see how the uaID number matches the id number over in the index table. The 'status' column data here, likewise in the other data tables, is what I need "linked" to the relevant 'status' column within the index table. So if it changes here, to become this:
appID uID uaID status
1 1 2 Data Acquisition
2 1 4 Pending Review
The index table would then become:
id appNo applicationKey applicationName uID status
1 3 AIGs2GRA A.I.G stage 2 Grant App 1 Data Acquisition
2 2 AIGs1PIA A.I.G stage 1 Process App 1 Data Acquisition
3 3 AIGs2GRA A.I.G stage 2 Grant App 1 Declined
4 2 AIGs1PIA A.I.G stage 1 Process App 1 Pending Review
5 3 AIGs2GRA A.I.G stage 2 Grant App 1 Data Acquisition
6 3 AIGs2GRA A.I.G stage 2 Grant App 1 Pending Review
7 8 VisFelAp Visiting Fellowship App 1 Data Acquisition
8 3 AIGs2GRA A.I.G stage 2 Grant App 1 Data Acquisition
9 8 VisFelAp Visiting Fellowship App 1 Accepted
Note how entry number 4 has also changed?
Simply use trigger on your specific column.
CREATE TRIGGER myTrigger AFTER UPDATE ON myTable
FOR EACH ROW
if NEW.column1 <> OLD.column1
begin
#new_index = NEW.youColumn
--put #new_index in your desired table using UPDATE statement
end
END
CREATE TRIGGER statusUpdateTrigger AFTER UPDATE on app_AIGs2GRA
FOR EACH ROW
BEGIN
IF NEW.status <> OLD.status
THEN
UPDATE status_index SET status = NEW.status
WHERE appNo = NEW.appID AND applicationKey = 'AIGs2GRA';
END IF;
END;
Here's a demo in a fiddle: http://sqlfiddle.com/#!9/768c2/1. Now you would need to create this trigger for each of the individual app tables, and specify the applicationKey in each trigger (unless its in another relation somewhere and you can grab it that way)
You can create triggers in phpMyAdmin the same way you run queries, just by executing the SQL
NOTE: Because the trigger contains semi-colons in the definition, you need to alter the delimiter that phpMyAdmin uses - http://phpsblog.agustinvillalba.com/create-triggers-phpmyadmin/ that page seems to show how to do that. This is why the schema in the fiddle has // to terminate some statements.

Update field in Table when conditions fulfilled in MS Access 2013

I have two tables in MS Access 2013.
Table of SERVICE:
(ID is the primary key)
ID PART_ID SERVICE_DATE REMARK WITHDRAWN
1 A0001 01/04/2014
2 A0002 01/04/2014
3 A0003 01/04/2014 SCRAP
4 A0004 01/04/2014
5 A0001 01/05/2014
6 A0002 01/05/2014
Table of WITHDRAW:
(ID is the primary key)
ID PART_ID DRAW_DATE
1 A0001 02/04/2014
2 A0002 02/04/2014
3 A0001 02/05/2014
I'd like to put a "NO" into the field of WITHDRAWN in Table of SERVICE to indicate the part has not been withdraw yet, if:
Part is first time in Table of SERVICE and never appear in Table of WITHDRAW.
Part appears few times in Table of SERVICE and Table of WITHDRAW, already serviced this time, not withdraw yet.
Part is not under category of "SCRAP".
Targetted Result:
Table of SERVICE
ID PART_ID SERVICE_DATE REMARK WITHDRAWN
1 A0001 01/04/2014
2 A0002 01/04/2014
3 A0003 01/04/2014 SCRAP
4 A0004 01/04/2014 NO
5 A0001 01/05/2014
6 A0002 01/05/2014 NO
But I just know how to write the code for the first condition:
UPDATE SERVICE LEFT JOIN WITHDRAW ON SERVICE.PART_ID = WITHDRAW.PART_ID SET SERVICE.WITHDRAWN = "NO" WHERE WITHDRAW.PART_ID Is Null;
Can somebody amend my code so that I can achieve the targetted result? Thanks!
I think what you are looking for is the following query:
UPDATE service
LEFT JOIN withdraw
ON service.part_id = withdraw.part_id
AND service.service_date <= withdraw.draw_date
SET service.withdrawn = "no"
WHERE withdraw.part_id IS NULL
AND Nz(service.remark, "") <> "scrap";
Your rules where a bit hard to understand, but I think I got it. I threw rule 1 and 2 together as follows:
1.Part is first time in Table of SERVICE and never appear in Table of WITHDRAW.
2.Part appears few times in Table of SERVICE and Table of WITHDRAW, already serviced this time, not withdraw yet.
==> The service_date of the part must be greater than the last withdraw_date for every part.

select 2 tables copy a unique number when records match

I have 2 tables 1. paypal_ipn_orders table 2 is lookup. The lookup table I have a list of all of my items with the column name item I also have another column labeled sort_id which is an 8 digit number used internally for all of my items. Table 1 paypal_ipn_orders receives orders and has several columns but only a few are important to the question. id, payer_email, item_name, sort_num and payment_status. What I need to happen is when an order comes into table paypal_ipn_orders I need to cross reference the lookup table and assign the 8 digit number into the column labeled sort_num when the item names match.
table: paypal_ipn_orders
id payer_email item_name sort_num payment_status
1 greg#gmail.com batman card NULL completed
2 steve#gmail.com superman card NULL completed
3 gary#gmail.com spiderman card NULL completed
4 sarah#gmail.com captain america NULL completed
here is the sample look up table
table: lookup
item sort_id
batman card 12345678
superman card 12345677
spiderman card 12345676
captain america 12345675
what I want the output to look like after I run the query.
table: paypal_ipn_orders
id payer_email item_name sort_num payment_status
1 greg#gmail.com batman card 12345678 completed
2 steve#gmail.com superman card 12345677 completed
3 gary#gmail.com spiderman card 12345676 completed
4 sarah#gmail.com captain america 12345675 completed
I know this isnt exactly the right syntax but you'll get the idea
SELECT lookup.sort_id
INSERT INTO paypal_ipn_orders.sort_num
WHERE lookup.item = paypal_ipn_orders.item_name
You need to use UPDATE, not INSERT:
UPDATE paypal_ipn_orders
SET sort_num = (SELECT sort_num
FROM lookup
WHERE lookup.item = paypal_ipn_orders.item_name)
Two side notes though:
Doing this will update the entire table. It would probably be best to do this in a trigger at the time of insert.
I wonder the benefit of storing the sort_num twice if the sort_num will always depend on the value in your lookup table. If you are trying to save the value at the time of insert or be able to manually change it though, it makes sense. (That is, if you change the sort_numin the lookup table, but you want to keep the original values in paypal_ipn_orders.)