Query of Queries Combinding Columns

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

  1. #1

    Default Query of Queries Combinding Columns

    I have two text files that I am using a cfhttp tag to query. I then need to
    combined the two queries to one query subtracting the "CHANGE" field from the
    second query from the "CHANGE" field in the first query. I will then use the
    combined query to create a new file. I can make the new file ok but cannot
    figure out how to subtract the two columns while combined them into one query.
    The two files have the same column names however the records form the first
    file might not have a match in the second file. I need to combine the records
    that match.

    I tried looping through the query and doing a query on the second checking it
    for a matching "PASS_NO" then subtracting the two "CHANGE" fields if there was
    a match but it times out on me.

    File one gets updated frequently and needs to be compared to file two each
    time it is updated.

    FILE STRUCTURE

    File One:
    FIRST_NAME,LAST_NAME,GUEST_NO,PASS_NO,ZIP,CHANGE

    File Two
    FIRST_NAME,LAST_NAME,GUEST_NO,PASS_NO,ZIP,CHANGE


    RECORD EXAMPLES (There are less than 100 records in file two and several
    hundred in file one)

    File One
    ALICIA,SMITH,55009,667020000,8364004000,7
    TOM,JONES,55976,692020000,8460004000,8
    ALLIE,JOHNSON,55419,703020000,119017000,5
    SKYE,DOE,55053,3007004000,8452004000,24

    File Two
    ALICIA,SMITH,55009,667020000,8364004000,2
    SKYE,DOE,55053,3007004000,8452004000,5


    Any help will be appreciated.FILE STRUCTURE

    tjestus Guest

  2. Similar Questions and Discussions

    1. Query of Queries
      I think that we're using 5 on both environments (not checked that though - they shouldn't be different anyway)... It seems that i've fixed it......
    2. query of queries with avg()
      cfmx 6.1 when i use avg() in a query of queries it rounds the results (actually rounds results down)...so i'm wondering if i am doing this...
    3. Query of Queries in 7.0
      I am running MX 6.1 and was wondering of the QofQ problem still exists (in the new version, 7.0) where CF tries to guess at the column datatype...
    4. Query of Queries on query New type query
      In CF5 we have a page that creates a query, using queryNew and querySetCell and the like, we then used dbtype="query" and gave it's name so we could...
    5. Query of Queries?
      I have a table named therapists with a field named modalities which contains a comma delimited list of id #s. I need to loop through a list of...
  3. #2

    Default Re: Query of Queries Combinding Columns

    why don't you use query of queries? The substraction part would be:

    select blah, blah, q1.change - q2.change as the change



    Dan Bracuk Guest

  4. #3

    Default Re: Query of Queries Combinding Columns

    Dan

    Thanks for the suggestion. I tried that once but kept getting and error using
    the "-" operator. I tried it again and this time added in some cfqueryparam
    tags to get it to read the fields as numbers in stead of characters (see code
    below). Now my problem is if I get over a few hundred records it times out on
    me. The estimate file sizes will be about 350 records in file two and 4,500 in
    file one. OUCH! Any idea on how to do this more effiecently?



    <cfquery name="q3" dbtype="query">
    SELECT q1.FIRST_NAME,q1.LAST_NAME,q1.GUEST_NO,q1.PASS_NO, q1.ZIP,(<cfqueryparam
    cfsqltype="cf_sql_numeric" value="#q1.CHANGE#"> - <cfqueryparam
    cfsqltype="cf_sql_numeric" value="#q2.CHANGE#">) AS NEWCHANGE
    FROM q1, q2
    </cfquery>

    tjestus Guest

  5. #4

    Default Re: Query of Queries Combinding Columns

    do the Q of Q, and include q1.change and q2.change in your select clause. Also
    include a constant number, 1000 for example, in the select clause. Give all
    these fields alias names.

    something like
    select q1.change as change1, q2.change as change2, 1000 as thedifference

    Then, loop through your new query and use querysetcell to change the value of
    the thedifference field.

    You'll only have to do it 350 times at most if that's the size of your smaller
    file, so it should be pretty quick.

    Dan Bracuk 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