Comparing current field data with last entry for field

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Comparing current field data with last entry for field

    Hi. I have a form that is inserting sales data on a daily basis. I have a
    field named "RoundTOTAL" which is the total sales for the day rounded to the
    nearest 100. I need to compare the "RoundTOTAL" that I am inserting for the
    current day with the "RoundTOTAL" for the previous day. Then, I need to input
    a value for a field representing whether the current day's "RoundTOTAL" is
    higher or lower than the previous day.

    My question is:
    How do I pull a field from the last entry in the database so that I can
    compare it to today's value?

    Thanks in advance for any help!

    ccnorris Guest

  2. Similar Questions and Discussions

    1. Formated Entry Field
      Hi, I'm working on an application and I need a formated entry field for partnumbers following a specific mask. I don't want to hardcode the mask...
    2. Controls like IE URL entry field
      Dear all I need to design a control like IE URL entry field. When I type "http://www.a" in URL, all the addresses have "http://www.a" would...
    3. comparing field values
      Hi I have a problem...I need to be able to compare the values entered in a series of fields against a set of rules. For example, lets say I have...
    4. Linking date field to text field entry
      Is there a way to setup a date field that will automatically enter the date when any information is entered into a field next to it?
    5. field entry
      Hello, I want enter data into a field in filemaker but have it displayed as asterisks. I know that there are several plug-ins that will allow...
  3. #2

    Default Re: Comparing current field data with last entry forfield

    There are a couple of ways to do this. If you know that there will be a record
    for the previous day, you can use ColdFusion to calculate the previous day and
    then query the database for this record. Another way is to query the database
    and order by the date field in descending order. The first record returned in
    this query would be the previous day.

    Once you get the record, you can compare the previous day's total with the
    current day and then insert the current day record.

    -Paul

    dempster Guest

  4. #3

    Default Re: Comparing current field data with last entry forfield

    why dont you use a date column in the same table to know each RoundTotal
    belongs to what date, the no mater how many RoundTotal you have and when you
    insert it in the Database you can always get two different dates and compare
    them.
    Alen

    Alen Guest

  5. #4

    Default Re: Comparing current field data with last entry forfield

    I do have a date column in the same table.

    Is there any way to compare the "RoundTOTAL" values BEFORE I insert the
    current "RoundTOTAL"? The result from the comparison needs to be inserted into
    the database at the same time that I insert the date, daily sales, total, and
    "RoundTOTAL".

    Sorry, for not completely comprehending your replies. I am still fairly new
    to CF and very new to comparing values from the database.

    ccnorris Guest

  6. #5

    Default Re: Comparing current field data with last entry forfield

    Why do you need to compare them before inserting into Database?
    Insert today's RoundTOTAL for what ever it is. Then make a select SQL command
    and get all records from yesterday and after.

    SELECT RoundTOTAL, sale_date
    FROM sales_Table
    WHERE sale_date >= '05-31-2005'


    you should get two records , one for yesterday and one for today. then compare
    them or do what ever you want with them.

    ps. check you database documentation to see what date format it expects. What
    I posted works on MySQL

    Alen Guest

  7. #6

    Default Re: Comparing current field data with last entry forfield

    I am creating a table that outputs the results. The compared RoundTOTAL values
    will determine the color of the row for that date. If the RoundTOTAL value for
    today is higher than the value from yesterday it will be assigned a value of
    "G" for green. If lower a value of "R" for red will be assigned. This is why
    I need to do the comparison before the Insert (if possible).

    ccnorris Guest

  8. #7

    Default Re: Comparing current field data with last entry forfield

    As I explained earlier, you can query the database in order to get the previous
    day's record and rounded total. Do this before you add the record for the
    current day. Once you get that total, you can figure out if it is higher or
    lower and then add your new record.

    If you are just doing this in order to display a row color, you could just
    handle that in the ColdFusion program that displays your output. Query the
    database for your records in order by date, ascending. Start your output. For
    each record you output, save the roundtotal in a variable such as
    prevroundtotal. Compare this variable with the roundtotal from the current
    record in order to show the row as green or red.

    That would be an easier way to handle it.

    -Paul

    dempster Guest

  9. #8

    Default Re: Comparing current field data with last entry forfield

    Paul,

    Thank you so much for your help and explanation! It works great!

    Carolyn
    ccnorris Guest

  10. #9

    Default Re: Comparing current field data with last entry forfield

    Alen,

    Thank you also for you help!

    Carolyn
    ccnorris 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