I am doing a lookup operation in BODS. The records that match need to be sent to a table and the ones that don't match need to be captured in a file.
Can you please help me out on how to capture the records that failed the lookup? It was easy in IBM Datastage but in SAP BODS its quite complex.
Look up is like a left Outer Join, it returns null for the non matching column from the right side table.
If you are matching records from Table A by doing look up to Table B, you must be fetching fields from Table B as well,
If the records are matching they will have values from table B, and those that doe not match will end having NULL values for Table B columns,
after separate the data with 2 Query transforms
**1) where Table B col is not null and load to the desired table
2) where Table B col is null and load Flat File.**
Related
Prolog:
I have two tables in two different databases, one is an updated version of the other. For example we could imagine that one year ago I duplicated table 1 in the new db (say, table 2), and from then I started working on table 2 never updating table 1.
I would like to compare the two tables, to get the differences that have grown in this period of time (the tables has preserved the structure, so that comparison has meaning)
My way of proceeding was to create a third table, in which I would like to copy both table 1 and table 2, and then count the number of repetitions of every entry.
In my opinion, this, added to a new attribute that specifies for every entry the table where he cames from would do the job.
Problem:
Copying the two tables into the third table I get the (obvious) error to have two duplicate key values in a unique or primary key costraint.
How could I bypass the error or how could do the same job better? Any idea is appreciated
Something like this should do what you want if A and B have the same structure, otherwise just select and rename the columns you want to confront....
SELECT
*
FROM
B
WHERE NOT EXISTS (SELECT * FROM A)
if NOT EXISTS doesn't work in your DBMS you could also use a left outer join comparing the rows columns values.
SELECT
A.*
from
A left outer join B
on A.col = B.col and ....
Suppose that I have two queries from two databases as below.
LIST 1 from [Alphabet] table
ABCD
A
B
C
D
LIST 2 from [Integers] table
Numbers
101
201
301
401
I would like to merge them so that in Excel sheet, I want to see that alphabet table is in columns A and integers table is in column B.
Here my suggestion:
Create Table merged ( Select [ABCD] from [Alphabet] join with [Numbers] from [Integers])
How can I improve the quality to work?
And should the row numbers be equal in both tables? Say, 27 letters and 27 integers, or would work with 27 letters and integers [1,20]?
This Is My First Answer and i hope it would help ...Back to your question
How can I improve the quality to work?
You Must use constraints to enforce rules for the data in your tables.
You need two columns of the same type, one on each table [Alphabet table] and [Integers table], to JOIN on.
Whether they're primary and foreign keys or not doesn't matter.
And should the row numbers be equal in both tables?
the answer is No
Depending on what joins you will Use !
SQL joins are used to query data from two or more tables, based on a relationship between the corresponding rows in these tables.
• INNER JOIN: Returns all corresponding rows from multiple tables.
• LEFT OUTER JOIN: Returns all rows from the left table, corresponding rows in the right table & if there are no matches, returns NULL.
• RIGHT OUTER JOIN: Returns all rows from the right table, corresponding rows in the left table, & if there are no matches, returns NULL.
Sorry for the confusing title, I think my question is a bit difficult to word. I have two tables, let's call them "A" and "B" and they each have many columns. For simplicity, let's say they have just columns "1" and "2".
Now for the fun part, I want to write an SQL query that for each numeric value in column 1 of table A checks to see if the values of column 2 of table A exist in column 2 of table B when filtered by that value of column 1. And if those values in table B do not exist, delete that row in table A.
For instance, the values of row 1 in each table are ID's of objects used elsewhere. When I filter by a specific ID in each tables, I see more rows in table A than I would like, the difference is column 2, which is an associated date. I want to delete those extra rows associated with the dates that are in A and not in B when I filter for that ID.
I can't just use a NOT IN or NULL statement like the ones used here:
Delete sql rows where IDs do not have a match from another table
or here:
Delete from table if the id doesn't exists in another table
because some all the values in each column of each table do exist somewhere in the other table, just not with the corresponding filter.
This is my first time asking a question on SE and I tried my best to explain but let me know if I can provide any other info! Thanks!
Ad far as I can tell, you want to delete from one table if there are no corresponding values in the other. This strongly suggests not exists (regardless of the database).
As best that I can parse your description:
delete from a
where not exists (select 1
from b
where b.col1 = a.col1 and b.col2 = a.col2
);
In my talned job I am copying data from Excel to SQL table.
For this job to maintain the foreign key constraint I had to do a look up before copying the data.
The task goes like this.
I have to copy data in Table2 (id keys value).
My excel sheet has data for id and keys column. Table 1 has two columns id and value.
For value column's data I want to look at Table1's corresponding entry with the id of the current record in Table2. I have to copy the data from Table1's value column to Table2's value column.
Excel (id 1 2 3, keys a b c)
Table_1 (id 1 2 3, value 123 456 789)
desired output: Table_2 (id 1 2 3, keys a b c, value 123 456 789)
current output: Table_2 (id 1 2 3, keys a b c, value null null null)
How do I properly map this?
You've set the job up exactly as needs to be done really so it's not your job layout that's the problem here.
If you're expecting every record in your Excel document to have a matching record in your database table then you should use an inner join condition in your tMap join like so:
And this then allows you to have an output that grabs everything that isn't joining (which is your issue here):
This should show you everything in your source (not lookup) file that isn't matching. I suspect that everything is failing to match on your join condition (essentially WHERE ExcelDoc.id = Table.Id) even if it looks like it should. This could be down to a mismatch of datatypes as they are read into Talend (so the Java/Talend datatypes such as int/Integer or String rather than the DB types) or because one of your id columns has extraneous whitespace padding.
If you find that your id column in one of your sources does in fact have any padding then you should be able to convert it in a previous step before your join or even just make the transformation in the join:
The only other thing I'd recommend is that you name your flows between components (just click on them to change the name), especially when you are joining anything in a tMap.
I have 2 sql tables( A and B) with no relation among them. I wanted to copy the data of one column of table B and merge it with the table A as a new column of able B
How do i do that.
I have tried to write this code -
Insert into TableA(ColumnC) select top 10 ColumnA from TableB