Link to home
Start Free TrialLog in
Avatar of bibi92
bibi92Flag for France

asked on

Query about select statement for insert missing records

Hello,

I want to detect the missing recordings in a table of destination by means of a select minus or where not in  but tables have no same structure and I shall wish to insert what misses:

insert into dbtarget.schematarget.table
select * ,
(
select name
From [ serversource ] .dbsource.sys.schemas
Objectpropertyex (object_id (' 01A.ACES ') where schema_id = ', SchemaId ')
) as folder from  [serversource] .dbsource.01A.ACES
Minus
select  * from dbtarget.schematarget.table where [ folder ] = ' 01A '

How can do this, do you have an example?
Thanks
bibi
ASKER CERTIFIED SOLUTION
Avatar of Nathan Riley
Nathan Riley
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bibi92

ASKER

but the target table doesn't have the same structure. thanks regards bibi
what are the columns in the target table?
Avatar of bibi92

ASKER

folder, it's the reason for that I add select name
From [ serversource ] .dbsource.sys.schemas
Objectpropertyex (object_id (' 01A.ACES ') where schema_id = ', SchemaId ')
 and a column in a source table has for name rowid and in the target table drowid.
Thanks
bibi
Didn't get you exactly. Could your explain with some sample data?
Avatar of bibi92

ASKER

I think I can create a temp table for add schema name and following do

insert into dbtarget.schematarget.table
select s.[ROW], o.[ROWID_0] from stmt_repl s
INNER JOIN ods.ODS.GAC o
on s.[ROW]=o.[ROWID_0]
and o.[DOS_0] = '01A'
where s.[ROW]  not in (select o.ROWID_0 from  ods.ODS.GAC)
Thanks
bibi
Avatar of bibi92

ASKER

from this example, I can write query after creating a table temp thanks bibi