我必须根据可以为空的值选择要联接的相应列。
详细说明:

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为空,则必须使用shoporders.DeliveryAddressId
有线索吗?
提前谢谢

最佳答案

ON coalesce(shoporders.InvoiceAddressId, shoporders.DeliveryAddressId) = shopaddresses.addressid

关于c# - SQL Server条件连接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12585746/

10-11 01:35