1

我有这个视图:创建视图为

SELECT
         p.pr_id
        ,p.arenda
        ,p.PlotArea
        ,p.OwnershipTitle
        ,p.Price
        ,p.NotaryCosts
        ,p.AgentFee
        ,p.CtrNO
        ,isnull(p.Price,0)-isnull(a.Price,0) as Diferente
        ,isnull(p.Price,0)+isnull(p.NotaryCosts,0)+isnull(p.AgentFee,0) as TotalCosts

from  nbProcuri p
      left JOIN nbAchizitii a
      ON p.PlotArea = a.PlotArea and p.CtrNo=a.CtrNo
where a.CtrNO is null and a.PlotArea is null

我想将这两个表与另一个名为 Cadastrial 的表相关联,其中我还有一个名为 PlotArea 的列。如果 p.PlotArea=c.PlotArea ,则 p.arenda 列应使用值“yes”更新自身,否则以 no 填充。这可能以某种方式吗?谢谢!

4

1 回答 1

1

像这样:

UPDATE p
SET p.arenda = CASE WHEN p.PlotArea IS NULL THEN 'no' -- For not matched 
                    ELSE 'yes' -- for matched
               END
FROM nbProcuri p
LEFT JOIN Cadastrial c ON p.PlotArea = c.PlotArea
LEFT JOIN nbAchizitii a
      ON p.PlotArea = a.PlotArea and p.CtrNo = a.CtrNo
WHERE a.CtrNO IS NULL 
  AND a.PlotArea IS NULL;
于 2012-12-11T15:19:46.120 回答