我想下面的是一些T-SQL語法正確的版本(希望是什麼波紋管是人類可讀)加入的T1,B和C,但只有在爲C JOIN如果c不爲空
select* from table1
join table2
on table1.a = table2.a
and table1.b = table2.b
and table1.c =
when table1.c IS NOT NULL THEN table2.c
when table1.c IS NULL THEN --dont join on column c, just use the other joins
END
I tried the syntax below but it doesn't seem to work (any explanation of why this is incorrect is also appreciated)
select* from table1
join table2
on table1.a = table2.a
and table1.b = table2.b
and table1.c =
when table1.c IS NOT NULL THEN table2.c
when table1.c IS NULL THEN null --this line is just guessing, but it doesnt work
end
這個完美的作品,雖然林不知道凝聚在做什麼(我假設如果沒有匹配檢查空?)。作爲後續,我將如何加入t2.c在t1.c他們都爲null?我知道我不能加入null,但這對於我正在處理的異常數據遷移非常有用 –
我已經爲答案添加了一些解釋,而不是試圖將所有內容都納入評論。 –