SQLTeam.com | Weblogs | Forums

Creating sql column entry from one database to another


#1

I need to run a SQL query to do the following

  1. Match 2 table column entries across two databases.
  2. Take the column entry from one database and insert it into a column entry on the other database and confirm that both entries now match across them.

So the details are
In ServiceManager DB Table “MT_System$Knowledge$Article”
match this column “ExternalURL_D83294A8_89AE_ED0D_8774_30C57ECD5361”
to in the ServiceManagement DB table “dbo.knowledgearticle” column “ExternalURL”
Take the value from this ServiceManager column “ArticleId_41C919C2_3E75_EEE4_E63F_E7947CB07DEF” in table MT_System$Knowledge$Article
and merge it into this ServiceManagement DB column “VendorArticleID” in “dbo.knowledgearticle”
I think this needs to look something like this
MERGE INTO YourTable T
USING (
SELECT id, col1, col2
FROM other_table
WHERE tsql = '#######'
) S
ON T.id = S.id
WHEN MATCHED THEN
UPDATE
SET col1 = S.col1,
col2 = S.col2;

I have basic SQL skills so apologise in advance. I feel this is probably very simple query


#2

So, you're not actually matching on ExternalURL?


#3

I got it working

MERGE INTO ServiceManagement.dbo.knowledgearticle T
USING ServiceManagement.dbo.[MT_System$Knowledge$Article] S
ON s.[ExternalURL_D83294A8_89AE_ED0D_8774_30C57ECD5361] = T.ExternalURL
WHEN MATCHED THEN
UPDATE
SET VendorArticleID = S.[ArticleId_41C919C2_3E75_EEE4_E63F_E7947CB07DEF];