所以我发现自己在做这样的事情:
SELECT
Foo =
CASE
WHEN a.Foo IS NULL THEN (SELECT x.Foo FROM x WHERE x.Id = a.Id)
ELSE a.Foo
END,
Bar =
CASE
WHEN a.Bar IS NULL THEN (SELECT x.Bar FROM x WHERE x.Id = a.Id)
ELSE a.Bar
END,
Alice =
CASE
WHEN a.Alice IS NULL THEN (SELECT x.Alice FROM x WHERE x.Id = a.Id)
ELSE a.Alice
END
FROM a INNER JOIN b ON a.X = b.X
那看起来不漂亮。所以我想知道是否有任何方法可以创建一个临时变量,例如:
WITH Temp AS SELECT * FROM x WHERE x.Id = a.Id
范围SELECT
和参考范围内吗?