Deleting specific rows from a returned query result

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

  1. #1

    Default Deleting specific rows from a returned query result

    I execute a <cfquery> statement block, and that works fine. However, I need to
    manipulate the return query rows by deleting the ones that do not meet specific
    requirements.

    Example:

    <!--- Create array to store references to data to delete --->
    <cfset deleteTrack = ArrayNew(1)>
    <cfloop index="i" from="1" to="#chartdata.RecordCount#">
    <cfif DateFormat(chartdata.searchdate, "full") LESS THAN SomeDate>
    <!--- store the location in the query in a new array to delete later --->
    <cfoutput>#ArrayAppend(deleteTrack, i)#</cfoutput>
    </cfif>
    </cfloop>
    <!--- Need to sort the array desc so the deleted array parts to not shift the
    other marked-for-deletion querys down --->
    <cfoutput>#ArraySort(deleteTrack, "numeric", "desc")#</cfoutput>
    <!--- Loop through the date row deleting all parts that didn't meet
    requirements --->
    <cfloop index="v" from="0" to="#ArrayLen(deleteTrack)#">
    <cfoutput>
    #ArrayDeleteAt(chartdata.date, deleteTrack[v])#
    </cfoutput>
    </cfloop>

    The error that I am getting is: "Object of type class java.lang.String cannot
    be used as an array"

    Why is the query of type string? Shouldn't it be of type Array? Anyone have a
    work around to deleting specific rows in query results. I need to manipulate
    the original query because I'm putting the values into a chart which uses the
    original query rows to display.

    madgett Guest

  2. Similar Questions and Discussions

    1. #37037 [Ana->WFx]: pgsql: Can't access result returned from an INSERT
      ID: 37037 Updated by: iliaa@php.net Reported By: shadda at gmail dot com -Status: Analyzed +Status: ...
    2. interogate result returned in DeltaPacket
      I need to determine what my database assigned to the key of a record that was just inserted. I can see in NetConnection Debugger, in the...
    3. How to limit # of rows returned from query
      I am looking at setting a limit to the number of rows returned on some of my queries. I was looking at doing something like: <cfoutput...
    4. How to use returned result sets from a client app?
      Hi there, In the IBM sample file (see /opt/IBM/db2/V8.1/samples/cpp), spserver.sqC, it implemented a routine called two_result_sets(...). In...
    5. limiting rows returned in a sql select
      ceprnatwork@hotmail.com (the dragon) wrote in message news:<6e59cc25.0308200651.6edb0e2@posting.google.com>... I dont know why "fetch first ...",...
  3. #2

    Default Re: Deleting specific rows from a returned query result

    Hi Madgett,

    Append the primary key of the record to the array, not the relative position.
    Then you can issue a delete statement like

    DELETE FROM ChartData
    WHERE PK IN(#arraytolist(deleteTrack)#)

    You do have a primary key field in the table, don't you?

    HTH,

    philh Guest

  4. #3

    Default Re: Deleting specific rows from a returned query result

    Keep in mind I'm not trying to delete anything from the database. I want that
    data to stay. However, I need to delete rows in the query result, after the
    SELECT statement, that do not meet specific criteria. I'm getting a String type
    error when trying to use ArrayDeleteAt on the query result
    "chartdata.fieldname". fieldname should be an array of rows, and you can access
    each piece of data like this: chartdata.fieldname, I can already to that and
    manipulate data that way. But, I want to delete fieldname in the chartdata
    result where i data doesn't meet the criteria. I can give it a "" value, but
    that's pointless with charts. So I need to delete it altogether and it's giving
    me a type error.

    Any more thoughts?

    madgett Guest

  5. #4

    Default Re: Deleting specific rows from a returned query result

    You might consider using a query-of-query to delete the specific rows of your original query so that you have both result sets to work with.

    Phil
    paross1 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