title: sql function how to return a string based on the condition of a value in the table
body: <p>I have this SQL table Invoice. What I'm trying to achieve is to write a function that you send a primary key value to to get  a particular invoice. Then I want to check a field of the Invoice 'Received' This is a bit field. If is 1 I want to return from the function 'Received'. If it is 0 I want to return 'Not Received'.</p>
  
  <p>I had a go at it myself:</p>
  
  <pre><code>ALTER FUNCTION dbo.InvoiceStatus(@InvoiceId INT)
  RETURNS VARCHAR
  BEGIN
  declare @Status varchar(100)
  
      SELECT * 
        FROM [Invoices_Prod].[dbo].[Invoice]
        Where InvoiceId = @InvoiceId
  
        ...
  
        How to check the received value?
  
        ...
  
      return @Status
  
  END
  GO
  </code></pre>
  
  <p>So I'm passing the InvoiceId in and getting a particular Invoice with the select statement. What I'm missing is how to checked the Received field and set the status value to be returned.</p>
  
  <p>Can anyone help me with this?</p>