title: sql-server, IF statement within SQL Query
body: <p>I'm having trouble with using an <code>IF</code> statement within this sql-server query.</p>
  
  <p>What I want:</p>
  
  <p>If <code>salesHeader.[Ship-to Name]</code> isn't null, I need to return that AS DeliveryName, if it is null, return something else.</p>
  
  <p>Is there a way to do this with an <code>if</code> statement in a query?</p>
  
  <pre><code>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_)
  </code></pre>