小编典典

SQL Server条件连接

sql

我必须根据可以为空的值选择相应的列以进行联接。详细地:

SELECT shoporders.orderid, 
   shopaddresses.companyname, 
   shopaddresses.firstname, 
   shopaddresses.lastname, 
   shopaddresses.address1,  
FROM   shoporders 
   INNER JOIN shopaddresses 
           ON shoporders.InvoiceAddressId = shopaddresses.addressid
where orderid = 110
order by shoporders.createddate desc

如果shoporders.InvoiceAddressId为null,那么我必须使用shoporders.DeliveryAddressId

有什么线索吗?

提前致谢


阅读 215

收藏
2021-04-28

共1个答案

小编典典

ON coalesce(shoporders.InvoiceAddressId, shoporders.DeliveryAddressId) = shopaddresses.addressid
2021-04-28