I have the following query, that makes up a View.
I'm having trouble with the IF statement within it. Basically, if salesHeader.[Ship-to Name] isn't null, i need to return that AS DeliveryName, if it is null, return something else.
There are several fields like this (i've only included one for now)
Is there a way of doing this?
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_)