Merging data from one table to another table with out any relation - sql

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

Related

Merge into multiple table using two different SELECT clause from a WITH statement (ORACLE)

I have a procedure refreshed daily, I want to insert / or merge into 2 table from a single source, but I don't want to create one then delete and insert data to a table just only for the source (T1 table) (I don't use that source table for reporting and it have many rows so the procedure might run slowly)
My desired result is:
Merge into or insert into 2 existing tables using
with t1 table
and two select query from that t1 table (the two select query have different purpose, one is map the detail (supposed group by ID) and one is group by month,... etc from t1 table)
From what I have researched so far, insert all only support single query and insert to multiple table, and merge into only merge into 1 table with 1 single query.
How to combine these?

Merging 2 SQL tables with same table convention design without using update command

I have 2 tables in my SQL database:
And I want to merge them in a way the result will be:
This is just an example for 2 tables which need to be merged into one new table (The tables contain an example data, the statement should work for any amount of data inside the tables).
The ID which got different value in CSV should be updated into the new table for example:
ID 3's value is 'KKK' and in table T is 'CCC', then what should be updated is the CSV table.
You seem to want a left join and to match to the second table if available:
select t.id, coalesce(csv.value, t.value) as value
from t left join
csv
on t.id = csv.id;
If you want this in a new table, use the appropriate construct for your database, or use insert to insert into an existing table.

How to capture rejected records in SAP BODS?

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.**

BEFORE or INSTEAD OF Insert SQL Server triggers

I have a small problem. What I want to achieve is before inserting data to table A, I want to check if this data is in table B and table C.
When tables B and C don't have this data, I'd like to add data from 'inserted' to table B and C (and insert data to table A at the end), but if they have already this row, I don't want to insert anything to table A and B (and don't know to insert anything to table A as well).
Is there any way I can control if the data from inserted will be inserted in table A or not?

SQL query to update one for one

I have table A with one to many relationship to table B. Whenever I do an update I create new record in table A with a new batch of records related created in table B. I had a bug in my code so when new items where being created the order of them was being reversed. I need to write a SQL query to update items in table B related to second item in table A to be the same as the ones related to first item in table A. I hope it makes any sense, will try to illustrate:
A1 -> B - 1234
A2 -> B - 4321
I want to update second set of values from table B to be the same as the ones related to A1 (1234)
You should not think of records order in database table. The only way to specify order of rows is ORDER BY clause in SELECT statement.
Make row_order or idx column in table B and put there required value for each item.
In some cases you will also get different order of B items for the first/source A record when selecting them without specifying order in ORDER BY clause.
Relational database table has no notion about neither row order nor column order.