Loop a Result Set Within a StoredProc

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

  1. #1

    Default Loop a Result Set Within a StoredProc

    I am trying to setup a storedproc that first joins a few tables in order to
    pull a select type of member from a master members list. I then want to take
    the loop that result set to get a count of where these members are from I have
    the first part down where we group by country then DISTINCT the state/province.
    Now I just need to run a second similar statement that will get the per state
    count. Results are set to output like such

    United States
    CA - 300 members
    NY - 200 members

    Canada
    MT - 50

    ETC. ETC.

    Below is my SP code I have so far. Any help is greatly apprecitated.

    CREATE PROCEDURE sp_user_report

    AS

    SELECT DISTINCT
    act_address.state,
    globals.dbo.country.country_name,
    globals.dbo.country.display_order
    FROM
    actor_access_user INNER JOIN act_actor ON
    actor_access_user.act_actor_id=act_actor.actor_id
    INNER JOIN act_address ON act_actor.address_id=act_address.address_id
    INNER JOIN globals.dbo.country ON
    act_address.country_id=globals.dbo.country.country _id
    GROUP BY
    act_address.country_id

    ORDER BY
    globals.dbo.country.display_order
    GO


    Warden Guest

  2. Similar Questions and Discussions

    1. StoredProc: How to pass 'table' as argument ?
      I have such StoredProc (Function) Is it possible to pass 'Table' to stored proc as argument? code ----------------------------- CREATE FUNCTION...
    2. loop count down until result is achieved
      I'm trying to figure this out and the problem is, the search function on these forums sucks so I can't find any answers. I have one static variable...
    3. Film loop rollovers working with tell sprite, but only if Loop is checked
      on mouseWithin me cursor 280 tell sprite 40 --the sprite containing the film loop sprite(60).member = member("networkmapsbuttonroll") --swapping...
    4. How to declare the result of a loop as a variable?
      I'm trying to include a list of people that's the result of looping through a recordset in a CDONTS mail. I'm trying to Dim the output of a loop,...
    5. factoring out a query result to reuse it in a loop
      Zeng, You can insert the results into a temp table or table variable and work with that in the loop. Linda
  3. #2

    Default Re: Loop a Result Set Within a StoredProc

    I don't think you need a loop. You should be able to get a per state count, by
    making a slight modification to your SELECT DISTINCT Query

    --- SQL is not tested
    SELECT c.country_name, addr.state, COUNT(*) AS TotalMembers
    FROM actor_access_user usr INNER JOIN act_actor act ON usr.act_actor_id =
    act.actor_id
    INNER JOIN act_address addr ON act.address_id = addr.address_id
    INNER JOIN globals.dbo.country c ON addr.country_id = c.country_id
    GROUP BY c.country_name, addr.state

    You could then use a CFOUPUT "group" to produce these results

    United States
    CA - 300 members
    NY - 200 members

    Canada
    MT - 50

    mxstu 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