IIF in SQL server.

Results 1 to 3 of 3

Thread: IIF in SQL server.

  1. #1
    Join Date
    Dec 1969

    Default IIF in SQL server.

    I am trying to determine if there is a date value in a field, if there is I want to return that value otherwise I want to return today&#039;s value, I can do it in Access using IIF, but how do I do it in SQL server. Books on Line gives an e.g. of IIF but the query analyser says it&#039;s not a recognized function name. Below is one of the attempts I have made ...<BR><BR>select IIf(Is null(MarkedCancelDate), getdate()), MarkedCancelDate))as CancelDate, *<BR>FROM CardCategory <BR><BR>Thanks in advance.

  2. #2
    Join Date
    Dec 1969

    Default CASE or ISNULL

    CASE would be the equivalent of IIF only it is a lot more like VBScript&#039;s SELECT CASE.<BR><BR>But, in this case - it sounds like you want to use SQL Server&#039;s ISNULL function:<BR>SELECT ISNULL(MarkedCancelDate, GETDATE()) As CancelDate, *<BR>FROM CardCategory<BR><BR>BTW, it is bad practice to use SELECT *, you should select the individual fields that you need to work with.<BR><BR>-Doug

  3. #3
    Join Date
    Dec 1969

    Default coalesce

    select coalesce(MarkedCancelDate,current_timestamp) as CancelDate<BR><BR>You can also look up case expressions in BOL.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts