two queries - one cfquery call

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

  1. #1

    Default two queries - one cfquery call

    I'm trying to do the following in one single cfquery call. However, I'm having
    trouble referencing "memberCount" in the Insert part of the statement. It
    keeps saying invalid column name "memberCount".

    How would I reference it correctly? Thanks.

    <cfquery>
    SELECT COUNT(1) AS memberCount
    FROM groupMembers
    WHERE groupId = #arguments.groupId#;

    UPDATE groupNames
    SET groupNumberOfMembers = memberCount
    WHERE groupId = #arguments.groupId#;
    </cfquery>


    alwaysconfused Guest

  2. Similar Questions and Discussions

    1. cfquery cache stores failed queries
      cfquery cache still stores failed queries. This was reported years ago...
    2. No escape character with dircect method call in cfquery
      Hello, I found the follwing behavior when I tried to use a method call directly in a <cfquery>. In this case single quote characers will not be...
    3. Queries Of Queries Single Quote Problem
      When using queries of queries I'm having the following issue. Select Company_ID From qry_MyQuery Where Company_NM = 'MyString''s' <----...
    4. Best way to call SQL queries
      Hi All I know this might sound strange, but I'm doing an ecom site and I'm actually going to use an Access Db in the development stages, because...
    5. remote call procedure call failed
      Also, it says error 1726 "remote call procedure call failed" Help, Unable to save username and password in XP Home edition. It allows me to...
  3. #2

    Default Re: two queries - one cfquery call

    alwaysconfused wrote:
    > I'm trying to do the following in one single cfquery call. However, I'm having
    > trouble referencing "memberCount" in the Insert part of the statement. It
    > keeps saying invalid column name "memberCount".
    >
    > How would I reference it correctly? Thanks.
    >
    > <cfquery>
    > SELECT COUNT(1) AS memberCount
    > FROM groupMembers
    > WHERE groupId = #arguments.groupId#;
    >
    > UPDATE groupNames
    > SET groupNumberOfMembers = memberCount
    > WHERE groupId = #arguments.groupId#;
    > </cfquery>
    >
    >
    I think you'd have to do something like this--this is assuming SQL Server:

    DECLARE @memberCount int
    SELECT @memberCount = COUNT(1)
    FROM groupMembers
    WHERE groupId = #arguments.groupId#

    UPDATE groupNames
    SET groupNumberOfMembers = @memberCount
    WHERE groupId = #arguments.groupId#

    I can't test that at the moment but I think that should get you rolling.

    Matt
    --
    Matt Woodward
    [email]mpwoodward@gmail.com[/email]
    Team Macromedia - ColdFusion
    mpwoodward *TMM* Guest

  4. #3

    Default Re: two queries - one cfquery call

    How about:
    UPDATE groupNames
    SET groupNumberOfMembers = (SELECT COUNT(1) FROM groupMembers WHERE
    groupID=#arguments.groupId# )
    WHERE groupID = #arguments.groupId#;

    or evenbetter , if you wanna do all groups:
    UPDATE groupNames
    SET groupNumberOfMembers = (SELECT COUNT(1) FROM groupMembers WHERE
    groupMembers.groupID =groupNames.groupID )


    ALi


    Ali Soylu Guest

  5. #4

    Default Re: two queries - one cfquery call

    Here is my suggestion
    <cfquery name="abc">
    alter table groupnames
    drop column groupnumberofmembers
    </cfquery>

    <cfquery>
    select groupname count(groupname) as membercount
    from groupmembers join groupnames using (groupid)
    where groupid = #arguments.groupid#
    group by groupid
    </cfquery>

    syntax varies with different databases.

    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