June 28, 2015 at 1:37 am
I have a hard time understanding your example, so I don't know if this is the answer you're looking for, but have you looked into the syntax for a MERGE statement? It gives you a lot of control over moving data from one table into another. When the data is not matched (doesn't exist in the destination table), you can do an INSERT, whereas if the data is matched (duplicate row), you can update it. There's more information here, give it a go...
https://msdn.microsoft.com/en-us/library/bb510625(v=sql.105).aspx
June 28, 2015 at 3:39 pm
mtlsql (6/28/2015)
I have a hard time understanding your example, so I don't know if this is the answer you're looking for, but have you looked into the syntax for a MERGE statement? It gives you a lot of control over moving data from one table into another. When the data is not matched (doesn't exist in the destination table), you can do an INSERT, whereas if the data is matched (duplicate row), you can update it. There's more information here, give it a go...https://msdn.microsoft.com/en-us/library/bb510625(v=sql.105).aspx
I agree. A merge should work. An example is below:
merge into table1 u -- destination table
using table2 uq -- source table
on u.account_number=uq.account_number -- condition to test
when not matched then insert
(
account_name,
account_number,
affiliate,
email_address,
phone_number,
staff_number,
create_date)
values (
uq.account_name,
uq.account_number,
uq.affiliate,
uq.email_address,
uq.phone_number,
uq.staff_number,
uq.create_date);
Br. Kenneth Igiri
https://kennethigiri.com
All nations come to my light, all kings to the brightness of my rising
July 10, 2015 at 9:23 am
You might be able to get away with the following:
INSERT INTO HFM_Auxiliar.dbo.HFM_Applications (Appname)
SELECT DISTINCT Appname
FROM hfm.dbo.HSX_DATASOURCES
EXCEPT
SELECT DISTINCT Appname
FROM HFM_Auxiliar.dbo.HFM_Applications
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
Viewing 3 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply