2016-04-17 146 views
-2

查詢有關發貨地址。如果收貨地址爲空,請使用帳單地址。我不知道如何做一個專欄作爲地址。使用送貨地址和帳單地址。這將需要與工會的條款進行創建SQL查詢

+2

使用['COALESCE()']( http://www.techonthenet.com/oracle/functions/coalesce.php)。 –

+2

請在所有列中顯示您的表格。如果不知道表的外觀,就無法確定SQL。 –

+0

你的問題不清楚。提供一個表模式,樣本數據和預期結果 – FLICKER

回答

0

Oracle和SQL Server:

Select 
Case 
    When DeliveryAddress is NULL then BillingAddress 
    Else BillingAddress 
End "Address" 
from tbl 

或者Oracle的情況下,只有,

Select COALESCE(DeliveryAddress, BillingAddress) "Address" from tbl 
+0

對於SQL Server,您還需要使用'is null',並且'as'是可選的。所以我建議後者'case'可以用於SQL Server和Oracle。 – user212514

+0

謝謝..已經編輯了相應的答案 – VenVig