February 7, 2017 at 2:18 pm
I have a table called temporary where it has 4 countries data information -- we have a unique column called database name
where it has different country name
Eg :Database
----------------
DB1
DB2
DB3
DB_COMMON
WHen i am trying to insert into main table i was trying to keep distinct but distinct will not remove duplicates in this case.
- may be planning to join it with itself try to exclude it for eg : if some country has data has common in both the databases-
i want to load only DB1 or DB2 or DB3 data into main table not DB_COMMON data.
how to do this?
Insert into dbo.Main
(value1,valu2)
select (value1,value2) from temp table.
February 7, 2017 at 2:30 pm
mcfarlandparkway - Tuesday, February 7, 2017 2:18 PMI have a table called temporary where it has 4 countries data information -- we have a unique column called database name
where it has different country nameEg :Database
----------------
DB1
DB2
DB3
DB_COMMONWHen i am trying to insert into main table i was trying to keep distinct but distinct will not remove duplicates in this case.
- may be planning to join it with itself try to exclude it for eg : if some country has data has common in both the databases-
i want to load only DB1 or DB2 or DB3 data into main table not DB_COMMON data.how to do this?
Insert into dbo.Main
(value1,valu2)
select (value1,value2) from temp table.
Not really enough information to really understand the problem you would like help with here. Your example data doesn't quite match your description. It is clear what you are expecting with regard to the main table. Perhaps you could sandbox the problem in an empty database, create the tables involved, populate it with sample data and work from there. At this point you could also script out the the tables and data and post those here along with your expected results. The first article I link to in my signature block will help you with the items we need to provide you with better answers and working code.
February 7, 2017 at 2:31 pm
mcfarlandparkway - Tuesday, February 7, 2017 2:18 PMI have a table called temporary where it has 4 countries data information -- we have a unique column called database name
where it has different country nameEg :Database
----------------
DB1
DB2
DB3
DB_COMMONWHen i am trying to insert into main table i was trying to keep distinct but distinct will not remove duplicates in this case.
- may be planning to join it with itself try to exclude it for eg : if some country has data has common in both the databases-
i want to load only DB1 or DB2 or DB3 data into main table not DB_COMMON data.how to do this?
Insert into dbo.Main
(value1,valu2)
select (value1,value2) from temp table.
Possibly using a semi-join? It's difficult to be sure without DDL, sample data etc.
INSERT dbo.Main
select t.Country
from temptable t
WHERE NOT EXISTS (select 1 from dbo.Main m where m.Country = t.Country)
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply