I have 5 tables in Source.Each table have PK_ID.I have to populate into destination.I populated the table into destination but
I want to make a metadata_table in SSIS.The schema of metadata_table -
2 columns- a) table name b) last PK_ID of that table.
in table name column all the 5 table's name should be there and in PK_ID column , last PK_ID of respective table.
How can I do in SSIS. Please help
EDIT:
I need to update the destination table by populating newly inserted data in source table only by comparing PK_Id of source table with the Pk_Id of metatable as shown below
if(Pk_id(Source_table)>Pk_id(Meta_table))
then insert in Destination table(only those records having Pk_id greater than PK_id of metatable) and Update the metatable too by inserting Max(PK_id) of source table.
I would create a Dataflow for this. I would add 5 OLE DB Source objects, each would return the MAX (PK_ID) (assuming that meets the requirement - "last" is ambigous).
They would also each include a dummy join column e.g.
SELECT
1 AS DUMMY_KEY
, MAX ( PK_ID) AS PK_ID1
FROM TABLE1
Then I would add 4 Merge Join transformations. Each would join a pair of the OLE DB Source objects, using the DUMMY_KEY as the join.
The result would be a single row with the 5 "last PK_ID" columns.
Related
I have two tables:
documents table
audits table.
audits table is a polymorphic table and has auditable_type and auditable_id which is linked to the id of documents table. audits table also has event and new_values column.
Here's the table schema.
documents table has user_defined_field JSON column.
My goal is I want to get the first 4 values of the status field in user_defined_field JSON column. There will be a column in the report of the web app to display the 1st Status, 2nd Status, 3rd Status, 4th Status.
So basically, it's like the documents table is join to audits table and should get the first 4 record of the document id and display it in the SQL select as status_1, status_2, status_3, and status_4
Thank you.
It is possible in mysql create a view that use the column of a table plus the result of another for explain data?
I explain what I mean with an example.
Table 1
Table 2
Table 3
I want to select the record of table 2 and use in addition of record of table 1 and insert the data of table 3, like this creating a view that update if i adding row to any table.
the number on the column is num from table3 from id1 table1 and id2 from table2
I have one table in which each row (event) has a unique (integer) ID. I have another table, which includes the same events, and I am trying to copy the ID column from the first table to the next with no luck. I have tried creating a blank column in the second table first and I have tried it without having a blank column prepared. When I run my queries, it will spin and say that it was successfully executed, but the column in the second table is never updated.
Here is my query:
insert into games2 game_id
(
select games.game_id as game_id
from
games2 join games
on games2.DATE = games.DATE and
games2.HOME = games.HOME and
games2.AWAY = games.AWAY
)
INSERT INTO Item (Name)
SELECT Item
FROM IName
I think this source would help you out Copy from one column to another (different tables same database) mysql
I'm having a sql task which insert a single row record into table A each time.
Following by a data flow task which read all of the records from a csv file and save it into table B.
My question - How do I get the primary key that inserted into table A and insert it into table B ?
*Can It be done by insert the records from csv and also the primary key from table A at the same time ?
If you can select from table A last inserted record (PrimaryKey). You can use in dataflow lookup element and in lookup element write query which gonna select your wanted PrimaryKey.
I am doing an insert from SQL server table to Oracle table, which has a sequence for its identity column. I have used OLDDB command as my destination and used the following query for insert into oracle table
Insert into tablename (id, col1,col2....) values (seq.nextval,?,?,...)
I mapped all parameters to source columns and it works like a charm including sequence generation for identity column.
My other requirement is that the sequence that was generated in the first table has to be mapped with another table for foreign key relation, as follows:
table 1
emp table with columns
empid ----------- generated from sequence
name suffix
table 2
empinfo table with column
empinfoid ---- generated from sequence
empid ----- id that was generated in table 1.
address
edulevel
Since I do not have any others common keys between these two tables, I cannot have lookup and pull empid from table 1 to table 2.
How can I insert empid (generated from sequence) into both tables in parallel? I tried with oledb command out parameter, but wasn't successful as the Oracle connection is unable to find output params.
Provided you run both insert statements are in the same session, you insert seq.currval in table2.