Is it possible to check a date in SQL? I'm trying to write a Microsoft SQL Server stored procedure which takes an account ID, and returns an authentication ticket and whether the ticket is expired.

Something like this:

SELECT Authentication.ticket, Authentication.TicketExpires &lt; getDate()
FROM Authentication WHERE Authentication.accountID = @id


The purpose is to return a row with two columns - the ticket, and a bit field (0 or 1) telling me whether the ticket is expired. This bit field isn't part of the table, the ticketExpires column is SMALLDATETIME.

Does anyone know the correct syntax for this?
I think this achieves what you're looking for. Hope this helps.

 SELECT
      Authentication.Ticket
      , CAST(CASE
           WHEN Authentication.TicketExpires &lt; GetDate() THEN 1
           ELSE 0
      END AS bit) AS 'IsExpired'
 FROM Authentication
 WHERE Authentication.accountID = @id