dealing with no records returned

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

  1. #1

    Default dealing with no records returned

    Hey All,

    I'm setting up a column in DB that gets populated by a number incremented by
    1, based on the last column value entered.
    My problem happend when there are no prior records in the table that match my
    select criteria from the query that determines the number to increment. I
    thought using an if statement with the recordset keywork would work, but its
    throwing an error that seems to make no sense. Please take a look at the code
    below if you dont mind and see if there is something blatently wrong.... (it
    may be my logic behind getting the last number too...)

    The error i get is: the value "" cannot be converted to a number
    and it references this line: <cfset new_sort_id = #getMaxsort.maxsortID# + 1>


    Here is my code:
    <cfquery datasource="####" name="getMaxsort">
    SELECT MAX(sort_id) as maxsortID FROM pages WHERE iid = #form.iid#
    </cfquery>

    <cfif getMaxsort.recordcount NEQ 0>
    <cfset new_sort_id = #getMaxsort.maxsortID# + 1>
    <cfelse>
    <cfset new_sort_id = 1>
    </cfif>

    rowbeast Guest

  2. Similar Questions and Discussions

    1. dealing with dates
      Hello list, I am having a problem coming up with a solution to compare and find the difference between two dates. One of the dates is a GMT...
    2. limiting the number of records returned
      Hi all, The problem I am having is that I built an online query system. The problem is if the search critera is to open or loose, the coldfusion...
    3. Display Returned Records
      What I have is a query that returns all the parts in a service tech's kit. I am then returing the records in a table to show all the components in...
    4. DIR MX: Dealing with scrollbars
      Hi, I have a text member which content changes each time the user clicks on a button. A scrollbar is attached to this text member. I use this...
    5. checking how many records are returned?
      Is there a way to check how many records are returned from a query to the database?
  3. #2

    Default Re: dealing with no records returned

    If there are no records in the table, SELECT MAX(sort_id) will return NULL.
    This "null" is converted to an empty string in CF. Since an empty string is
    not a number, CF complains when you try to add "+1"

    <cfset new_sort_id = #getMaxsort.maxsortID# + 1>

    Use the val() function. It will convert the empty string to zero. However,
    using an auto incrementing id column would probably be easier than doing this
    all manually.

    <cfset new_sort_id = val(getMaxsort.maxsortID) + 1>



    mxstu Guest

  4. #3

    Default Re: dealing with no records returned

    thanks Stu, that makes total sense!
    I am not using an autoincrementing field as I will be modifing the values at a
    later time with a different query for sorting records, but thanks for the
    suggestion!



    rowbeast 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