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

  1. #1

    Default SQL problem...

    <cfquery name="QBDQuery" datasource="Quotes">
    SELECT QUOTE_TRACK.SalesNumber, QUOTE_TRACK.CustomerNumber,
    QUOTE_TRACK.Scopes, SUM(QUOTE.ExtPrice)
    FROM QUOTE_TRACK, QUOTE
    WHERE ((Quote_Track.QuoteDate BETWEEN ###FORM.StartDate### AND
    ###Form.EndDate###)
    AND (QUOTE_TRACK.QuoteNumber = QUOTE.QuoteNumber))
    ORDER BY QUOTE_TRACK.QuoteDate DESC, 1
    </cfquery>

    I'm trying to get some "Who it's To" information from the Quote_Track table
    and the SUM of the ExtPrice column in the Quote table so I can generate a
    report of the quotes that each salesman did for a given period of time, which
    instrument the quote was on, and the total dollar amount that the quote was
    for.

    I've tried inner joins and I've tried just shouting "Give me the right GD
    answer, you SOB. Whatever I do, I just get an error. Please help!

    Thanks
    Brendan

    Scamp Guest

  2. Similar Questions and Discussions

    1. contribute problem - access denied file may not existpermission problem
      Recieving the following error message - "access denied file may not exist , or there could be a permission problem" this happened this morning ,...
    2. Problem playing Quicktime thru .DCR embedded in HTML - pathreferencing problem?
      Greetings earthlings and Director heads. Here's the problem: created an HTML file containing shockwave (dcr) movie that calls quicktime movies in...
    3. Uploading problem = weird warning (was: access denied problem.....)
      Hi, I had a problem where my upload form was not working on our production server but was working on two other servers, after checking the...
    4. #21611 [Opn]: Problem with version_compare() (Was: Problem with pear cli and release numbers)
      ID: 21611 Updated by: et@php.net -Summary: Problem with pear cli and release numbers Reported By: jan at horde...
    5. Problem with Apache Web Server config file and PHP (please give advice on what problem may be me)
      HI: Can anyone refer me to someone that can help with the problem below. I installed Apache Web Server on my laptop which has Windows XP. I...
  3. #2

    Default Re: SQL problem...

    Does this work any better for you?

    <cfquery name="QBDQuery" datasource="Quotes">
    SELECT qt.SalesNumber, qt.CustomerNumber, qt.Scopes, SUM(q.ExtPrice)
    FROM QUOTE_TRACK qt, QUOTE q
    WHERE qt.QuoteDate BETWEEN #createodbcdatetime(FORM.StartDate)#
    AND #createodbcdatetime(Form.EndDate)#
    AND qt.QuoteNumber = q.QuoteNumber
    GROUP BY qt.SalesNumber, qt.CustomerNumber, qt.Scopes
    ORDER BY 1
    </cfquery>

    I abbreviated it a little by using table aliases, and "fixed" your dates (I
    hope), and added a GROUP BY clause, since you are attempting to SUM, and
    changed your ORDER BY, since I don't know how you can sort on a field that you
    didn't SELECT.

    I hope that this does the trick.

    Phil

    paross1 Guest

  4. #3

    Default Re: SQL problem...

    Phil - it works differently in that it gives me different error messages. I
    forgot to mention that I'm doing this in Dreamweaver 8 and using an Access
    database. The new errors have to do with my output query, which looks like
    this:

    <cfoutput query="QBDQuery">
    <tr>
    <td width="25%"><div
    align="center"><strong>#QBDQuery.QuoteNumber#</strong></div></td>
    <td width="25%"><div
    align="center"><strong>#DateFormat(QBDQuery.QuoteD ate,"M/D/YYYY")#</strong></div
    > </td>
    <td width="25%"><div
    align="center"><strong>#QBDQuery.SalesNumber#</strong></div></td>
    <td width="25%"><div align="center"><a
    href="FQWCD.cfm?QuoteNumber=#QBDQuery.QuoteNumber# "><strong>#QBDQuery.Scopes#</s
    trong></a></div></td>
    <td width="25%"><div
    align="center"><strong>#DollarFormat(QBDQuery.Expr 1003)#</strong></div></td>

    </tr></cfoutput>

    First, it tells me that QuoteNumber is undefined within QBDQuery. I can live
    with that, so I whack that part of the report and run it again. Another error.
    This time QuoteDate is undefined, and I can already see that the rest of the
    stuff will also be undefined. So I figure I'll just go into the query and
    define the missing jewels. Then they won't be undefined anymore. WRONG! Now
    it won't even load at all.

    My report as it is right now works well with ###Form.StartDate### &
    ###Form.EndDate###. But it has no total dollars field and that's the thing I
    want so I can see if the salesman is quoting things that are going to make
    money or if he's just filling up the system with BS. The report now only uses
    data from the Quote_Track table.

    Thanks for your help. My one remaining hair also thanks you.

    Brendan



    Scamp Guest

  5. #4

    Default Re: SQL problem...

    You should alias the SUM() column so that you can use that name...

    <cfquery name="QBDQuery" datasource="Quotes">
    SELECT qt.SalesNumber, qt.CustomerNumber, qt.Scopes, SUM(q.ExtPrice) AS
    tot_dollars
    FROM QUOTE_TRACK qt, QUOTE q
    WHERE qt.QuoteDate BETWEEN .....
    ...
    </cfquery>

    Plus, since you are already defining the query in your CFOUTPUT tag, you don't
    need to use it in your output. also, if you want to use fields in the output,
    you need to select them in your query, so that is why you are getting undefined
    on things like QuoteNumber and QuoteDate, etc.

    Your output might look something like this if you fix your query and add the
    appropriate fields to your select statement:

    <cfoutput query="QBDQuery">
    <tr>
    <td width="25%"><div align="center"><strong>#QuoteNumber#</strong></div></td>
    <td width="25%"><div
    align="center"><strong>#DateFormat(QuoteDate,"M/D/YYYY")#</strong></div></td>
    <td width="25%"><div align="center"><strong>#SalesNumber#</strong></div></td>
    <td width="25%"><div align="center"><a
    href="FQWCD.cfm?QuoteNumber=#QuoteNumber#"><strong >#Scopes#</strong></a></div></
    td>
    <td width="25%"><div
    align="center"><strong>#DollarFormat(tot_dollars)# </strong></div></td>
    </tr>
    </cfoutput>

    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