我在使用这个sql-server查询中遇到了使用
我的要求是:
如果
是否有一种方法可以在查询中使用
IF
语句的问题。我的要求是:
如果
salesHeader.[Ship-to Name]
不为null,我需要将它作为DeliveryName返回,如果它为null,则返回其他内容。是否有一种方法可以在查询中使用
if
语句实现呢?SELECT
poHeader.No_ AS PONumber,
poHeader.[Buy-from Vendor No_] AS VendorNumber,
poHeader.[Document Date] AS DocDate,
salesHeader.GiftMessage,
salesHeader.[Delivery Comment] AS DeliveryComment,
salesHeader.[Shipment Date] AS DeliveryDate,
IF salesHeader.[Ship-to Name] IS NOT NULL
salesHeader.[Ship-to Name] AS DeliveryName
ELSE
poHeader.[Ship-to Name] AS DeliveryName
END
FROM
dbo.[Crocus Live$Purch_ orders for e-mailing] AS poForEmailing
LEFT OUTER JOIN
dbo.[Crocus Live$Purchase Header] AS poHeader ON poForEmailing.No_ = poHeader.No_
INNER JOIN
dbo.[Crocus Live$Vendor] AS vendor ON poHeader.[Buy-from Vendor No_] = vendor.No_
LEFT OUTER JOIN
dbo.[Crocus Live$Sales Header] AS salesHeader ON salesHeader.No_ = dbo.fnGetSalesOrderNumber(poHeader.No_)