Query Issue - HELP PLS

Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default Query Issue - HELP PLS

    Hello All, I need someones help with this one please! I have a dB in Access
    that I need to query.
    I need to get all of the Approved Ingredients for a region and sub the
    ingredients quanity's. I will be passing in a URL var for the Region ID.

    Below is a query that works like BUTTA when I do it by the User. But now,
    ofcourse, I have to do it for a whole region.



    <!--- START This is the new SUM query from the approved_ingredients table.--->
    <cfquery name="qList_Ingredients_Sum" datasource="#Application.DataSource#">
    SELECT recipes.recipe_name AS recipe_name,
    recipes.recipe_id AS recipe_id,
    recipes.number_served AS number_served,
    recipes.last_day_to_sign_up_for AS last_day_to_sign_up_for,
    recipes.recipe_instructions AS recipe_instructions,
    recipes.active_recipe,
    recipe_ingredients.recipe_ingredient_id,
    recipe_ingredients.recipe_id,
    recipe_ingredients.ingredient_id,
    recipe_ingredients.active_ingredient AS active_ingredient,
    ingredients.ingredient_id,
    ingredients.ingredient AS ingredient_name,
    SUM(approved_ingredients.ingredient_quantity) AS ingredient_quantity,
    approved_ingredients.ingredient_id,
    approved_ingredients.ingredient_unit AS ingredient_unit,
    recipes_signed_up_for.recipe_id,
    recipes_signed_up_for.user_id,
    users.user_id
    FROM recipes, recipe_ingredients, ingredients, approved_ingredients,
    recipes_signed_up_for, users
    WHERE recipes.recipe_id = recipe_ingredients.recipe_id
    AND recipe_ingredients.ingredient_id = ingredients.ingredient_id
    AND approved_ingredients.user_id = #url.user_id#
    AND approved_ingredients.ingredient_id =
    recipe_ingredients.recipe_ingredient_id
    AND recipes.recipe_id = recipes_signed_up_for.recipe_id
    AND recipes_signed_up_for.user_id = users.user_id
    AND recipes_signed_up_for.user_id = #URL.user_id#
    AND recipes_signed_up_for.participate = 1
    AND recipes_signed_up_for.authorized
    GROUP BY recipe_ingredients.ingredient_id,
    recipes.recipe_ID,
    recipes.recipe_name,
    recipes.number_served,
    recipes.last_day_to_sign_up_for,
    recipes.recipe_instructions,
    recipes.active_recipe,
    recipe_ingredients.recipe_ingredient_id,
    recipe_ingredients.recipe_id,
    recipe_ingredients.active_ingredient,
    ingredients.ingredient_id,
    ingredients.ingredient,
    approved_ingredients.ingredient_id,
    approved_ingredients.ingredient_unit,
    recipes_signed_up_for.recipe_id,
    recipes_signed_up_for.user_id,
    users.user_id
    ORDER BY recipe_ingredients.ingredient_id
    </cfquery>


    <cfquery name="qList_Ingredients_Sum_final" dbtype="query">
    select ingredient_name, ingredient_unit, sum(ingredient_quantity) as abc
    from qList_Ingredients_Sum
    group by ingredient_name, ingredient_unit
    </cfquery>
    <!--- END This is the new SUM query from the approved_ingredients table.--->

    kingjes Guest

  2. Similar Questions and Discussions

    1. Query of Queries syntax issue
      I have query 1 which has a list of names and query 2 which has ratings for the names. Every rating from query 2 has a name in query 1, but not...
    2. Fusebox/query issue
      I have a fusebox site and I am trying to get a .swf file to load in one of my dsp files. The .swf file is using a query file. When my dsp page...
    3. Coldfusion MX 6.1 Query of Queries issue
      does any1 know if mx7 has fixed the query of queries runtime error issue which became apparant in mx6.1, where ColdFusion seemed not able to...
    4. Issue with AS/400 DB2 query | ByteArray object error
      We are running MX6.1 and just came across an error from data retrieved from our AS/400 (iSeries). We are receiving the 'ByteArray objects cannot be...
    5. CAML Query: Multiple Query Fields Issue
      I need to Create a CAML Query Dynamically with VB to a Sharepoint WebService GetListItems Method. The User Could Select 1 to X Number of IDs...
  3. #2

    Default Re: Query Issue - HELP PLS

    Here is what I have so far, with the results under that:

    <cfquery name="qList_Ingredients_Sum" datasource="#Application.DataSource#">
    SELECT recipes.recipe_name AS recipe_name,
    recipes.recipe_id AS recipe_id,
    recipes.number_served AS number_served,
    recipes.last_day_to_sign_up_for AS last_day_to_sign_up_for,
    recipes.recipe_instructions AS recipe_instructions,
    recipes.active_recipe,
    recipe_ingredients.recipe_ingredient_id,
    recipe_ingredients.recipe_id,
    recipe_ingredients.ingredient_id,
    recipe_ingredients.active_ingredient AS active_ingredient,
    ingredients.ingredient_id,
    ingredients.ingredient AS ingredient_name,
    SUM(approved_ingredients.ingredient_quantity) AS ingredient_quantity,
    approved_ingredients.ingredient_id,
    approved_ingredients.region_id,
    approved_ingredients.ingredient_unit AS ingredient_unit,
    recipes_signed_up_for.recipe_id,
    recipes_signed_up_for.user_id,
    users.user_id
    FROM recipes, recipe_ingredients, ingredients, approved_ingredients,
    recipes_signed_up_for, users
    WHERE recipes.recipe_id = recipe_ingredients.recipe_id
    AND recipe_ingredients.ingredient_id = ingredients.ingredient_id
    AND approved_ingredients.region_id = #url.region_id#
    AND approved_ingredients.ingredient_id =
    recipe_ingredients.recipe_ingredient_id
    AND recipes.recipe_id = recipes_signed_up_for.recipe_id
    AND recipes_signed_up_for.user_id = users.user_id
    AND recipes_signed_up_for.user_id IN (SELECT user_id
    FROM users
    WHERE region_id = #url.region_id#)
    AND recipes_signed_up_for.participate = 1
    AND recipes_signed_up_for.authorized = 1
    GROUP BY recipe_ingredients.ingredient_id,
    recipes.recipe_ID,
    recipes.recipe_name,
    recipes.number_served,
    recipes.last_day_to_sign_up_for,
    recipes.recipe_instructions,
    recipes.active_recipe,
    recipe_ingredients.recipe_ingredient_id,
    recipe_ingredients.recipe_id,
    recipe_ingredients.active_ingredient,
    ingredients.ingredient_id,
    ingredients.ingredient,
    approved_ingredients.ingredient_id,
    approved_ingredients.ingredient_unit,
    recipes_signed_up_for.recipe_id,
    recipes_signed_up_for.user_id,
    users.user_id,
    approved_ingredients.region_id
    ORDER BY ingredients.ingredient
    </cfquery>

    <cfquery name="qList_Ingredients_Sum_final" dbtype="query">
    SELECT region_id,
    ingredient_name,
    ingredient_unit,
    sum(ingredient_quantity) as abc
    FROM qList_Ingredients_Sum
    WHERE region_id = #url.region_id#
    GROUP BY ingredient_name, ingredient_unit, region_id
    </cfquery>

    <cfoutput query="qList_Ingredients_Sum_final" group="ingredient_name">
    #ingredient_name# #qList_Ingredients_Sum_final.abc# #ingredient_unit#<br>
    </cfoutput>

    kingjes Guest

  4. #3

    Default Re: Query Issue - HELP PLS

    1 Percent Milk 16 Quart
    Broccoli 70 Bundle
    Brown Sugar 6 Box
    Cornstarch 9 Box
    Garlic Powder 16 Container
    Lemon Juice 6 Container
    Margarine 16 Container
    Orange Juice (unsweetened) 9 Container
    Potato 587 Each
    Salsa (fresh) 35 Container
    Salt 12 Container
    Seasoned Salt 16 Container
    Shredded Cheese 35 Bag
    Sour Cream 35 Container
    Sweet Potato 21 Pound
    Vegetable Cooking Spray 6 Can
    Vegetable Oil 16 Container
    Yogurt (plain) 30 Container

    kingjes Guest

  5. #4

    Default Re: Query Issue - HELP PLS

    Here is a link to the relationships:

    [url]http://cvwebsolutions.com/temp/MCOE_Relationships.gif[/url]
    kingjes Guest

  6. #5

    Default Re: Query Issue - HELP PLS

    If anyone can help me out here!!
    kingjes Guest

  7. #6

    Default Re: Query Issue - HELP PLS

    I got it worked out. Thank goodness! It was a pain but I finally got it. My
    major issue was the ingreditnt_ id relationships.. it was changed up between
    the different tables.
    here is the way I didi it.

    <cfquery name="qList_Ingredients_Sum" datasource="#Application.DataSource#">
    SELECT DISTINCTROW
    approved_ingredients.Approved_ingredients_id,
    approved_ingredients.user_id,
    approved_ingredients.recipe_id,
    approved_ingredients.ingredient_id,
    approved_ingredients.region_id,
    approved_ingredients.ingredient_unit,
    Sum(approved_ingredients.ingredient_quantity) AS Sum_Of_ingredient_quantity,
    ingredients.ingredient AS ingredient_name
    FROM approved_ingredients, ingredients, recipes, recipe_ingredients
    WHERE recipes.recipe_id = recipe_ingredients.recipe_id
    AND recipe_ingredients.ingredient_id = ingredients.ingredient_id
    AND approved_ingredients.ingredient_id =
    recipe_ingredients.recipe_ingredient_id
    AND approved_ingredients.region_id = 33
    GROUP BY approved_ingredients.Approved_ingredients_id,
    approved_ingredients.user_id,
    approved_ingredients.recipe_id,
    approved_ingredients.ingredient_id,
    approved_ingredients.ingredient_unit,
    approved_ingredients.region_id,
    ingredients.ingredient
    ORDER BY approved_ingredients.ingredient_id
    </cfquery>

    <cfquery name="qList_Ingredients_Sum_final" dbtype="query">
    SELECT ingredient_name,
    ingredient_id,
    region_id,
    ingredient_unit,
    sum(Sum_Of_ingredient_quantity) as abc
    FROM qList_Ingredients_Sum
    WHERE region_id = 33
    GROUP BY ingredient_unit, region_id, ingredient_id, ingredient_name
    </cfquery>

    <cfoutput query="qList_Ingredients_Sum_final" group="ingredient_id">
    #ingredient_name# #ingredient_id# -- #abc# #ingredient_unit#<br>
    </cfoutput>

    kingjes 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