我有一个查询,用于在新数据库中为正确的广告获取正确的类别,但是一些受影响的行可能有多个类别,而有些可能没有,研究给了我使用'table.column 的信息+ your_data',这似乎带来了副作用,因为它不会更新 NULL 列,即使它说影响了正确数量的行..
SQL:
MERGE INTO sites.dbo.ads
USING (
SELECT e.name
FROM Database1.dbo.education AS e
INNER JOIN releducationcategory AS re ON e.educationid = re.educationid
INNER JOIN category AS c ON re.categoryid = c.categoryid
INNER JOIN string AS s ON c.categoryid = s.identifier
WHERE (s.string = 'Biologi, Fysikk & Kjemi') AND (e.site = 'sd')
) AS source
ON Database2.dbo.ads.name COLLATE Finnish_Swedish_CI_AS = source.name COLLATE Finnish_Swedish_CI_AS
WHEN MATCHED THEN
UPDATE
SET sites.dbo.ads.category = ', biologi-fysikk-kjemi';
当该列为 NULL 时,该更新运行良好,但是当已经有一个值时,它将被覆盖。当我将其更改为以下时:
SET sites.dbo.ads.category = sites.dbo.ads.category + ', biologi-fysikk-kjemi';
它只是更新不具有 NULL 值的行.. 但是它确实说影响了相同数量的行.. 怎么办?我应该做案例吗?