IIF in Select Query Error

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default IIF in Select Query Error

    Hello,

    I need to create a query with a date calculation of elapsed minutes. And, I
    have made this work. Now I find that some of the calculations come up with
    large negative numbers since one of the values may be "1800-01-01 00:00:00.0".
    I am attempting to add the IIF syntax to make the resultant value equal zero if
    the calculation was a negative number. But, I am getting a syntax violation at
    the "<" character. Any ideas?

    Thanks!
    -------------------------------------------


    <cfquery name="qryGetDay" datasource="MyDatasource">
    SELECT RADIONAME, DISPDATE, DISPDATE, RTQDate, IIF(DateDiff("n", DISPDATE,
    RTQDate) < 0, 0, DateDiff("n", DISPDATE, RTQDate)) AS TotalMins
    FROM DBTable
    WHERE DISPDATE BETWEEN #CreateODBCDateTime(GetDateBegin)# AND
    #CreateODBCDateTime(GetDateEnd)#
    AND RADIONAME IN ('#Replace(UnitList, ",", "','", "All")#')
    ORDER BY RADIONAME
    </cfquery>

    mcalpin Guest

  2. Similar Questions and Discussions

    1. Query of Query to select a title first letter
      The column "title" exists in a normal query. Need to select the first letter of the titles to build a list for a prev-next alphabetical search. ...
    2. Select query
      I would like to perform select on the following two tables, tblPoll PollID tblPollResults PollID AnswerID UserID
    3. update and insert query error, but select works ok.
      :rose; Any ideas spring to mind about the following issue? I'm getting an error trying to run an Update or Insert query. I can run a Select...
    4. SELECT query Error, possible date problem?
      Hello, I have what I thought was a fairly straight forward date based query that is returning an error I cant seem to get past. Here is my...
    5. SELECT DISTINCT + ORDER BY gives ERROR 145: ORDER BY items mustappear in the select list if SELECT DISTINCT is specified.
      Dan, You should be able to do this: SELECT Id, FaxID, ReceivedTime, Pages FROM ( SELECT DISTINCT .Id AS Id,
  3. #2

    Default Re: IIF in Select Query Error

    The problem is that IIf is a ColdFusion function. You need to use logic that
    works with your database. If you are using SQL Server, the following should
    work instead:

    CASE WHEN DateDiff(minute, DISPDATE, RTQDate) < 0 THEN 0 ELSE DateDiff(minute,
    DISPDATE, RTQDate) END

    Luckily, SQL Server has a DateDiff function as well.

    TA-Selene Guest

  4. #3

    Default Re: IIF in Select Query Error

    That worked (the crowd goes wild). Thanks a lot! John
    mcalpin Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139