SQL Server counting records

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default SQL Server counting records

    Hi
    I'm building a very basic forum with asp.net, The forum db is SQL2000 with 4
    tables
    users, forum, topics, replys
    I have everything working fine with the exception of counts
    On the forum page I have a repeater listing each entry in the forums table
    I would like to show a count of the number of topics for each forum
    Example:
    Test Forum (45 Topics last post by Jo Bloggs)
    Test Forum 2 (9 Topics last post by Joanne Bloggs)

    Is it easier to add a field to the forums table called topicCount and update
    that number everytime a new post is made or is there an easy way to build
    the count into my stored procedure

    Thanks in advance for any help received


    hoohim Guest

  2. Similar Questions and Discussions

    1. counting down in a for
      Hi all there is probably a much better way of doing all this i am working on the checkResults sub. it should find the pollerAudit log created...
    2. Counting (easy!)
      I'm sure this is easy but I'm a newbie. I was doing control statements (for, while,etc.) like this: for ($count = 1; $count <= 5; $count++) {...
    3. Counting (easy!) (YES!!)
      I think I figured it out! A FIRST!! for ($i = 1; $i <= 5; $i++){ sleep 1; print "$i\n"; } I prints out like this: 1...2...3...4...5
    4. COUNTING PROBLEM !!!
      I have a serious problem: Each time I run the following query the count result is changing! SELECT count(*) from posnad WHERE lfn_pos IS NULL ...
    5. Counting 1st Record only
      Hello, I am trying to write a query which will identify only those members who have used either one or more services in a given year. 1 MemberID...
  3. #2

    Default Re: SQL Server counting records

    You should be able to write one sql statement to reveal the count for the
    children (topics) of the parent table (forum), relating the tables and creating
    a group by clause.. As it is used here, the group by clause aggregates the
    values in the the parent's child table. For example, SELECT FORUM. NAME,
    FORUM, DESCRIPT, FORUM.CREATION_DT, COUNT(*) AS TOPIC_CNT FROM FORUM LEFT OUTER
    JOIN TOPICS ON FORUM.ID=TOPICS.FORUM_ID GROUP BY FORUM. NAME, FORUM, DESCRIPT,
    FORUM.CREATION_DT A RESULTING RECORDSET SAMPLE FOR THIS QUERY COULD BE AS
    FOLLOWS NAME DESCRIPT CREATION_DT TOPIC_CNT science
    science stuff 1/1/2001 5 politics worse
    stuff 2/2/2002 3 the topic cnt field represents how
    many topic there are in each forum

    RichMcCrea Guest

  4. #3

    Default Re: SQL Server counting records

    Excellent, many thanks


    "RichMcCrea" <webforumsuser@macromedia.com> wrote in message
    news:cvouhm$ogc$1@forums.macromedia.com...
    > You should be able to write one sql statement to reveal the count for the
    > children (topics) of the parent table (forum), relating the tables and
    > creating
    > a group by clause.. As it is used here, the group by clause aggregates the
    > values in the the parent's child table. For example, SELECT FORUM. NAME,
    > FORUM, DESCRIPT, FORUM.CREATION_DT, COUNT(*) AS TOPIC_CNT FROM FORUM LEFT
    > OUTER
    > JOIN TOPICS ON FORUM.ID=TOPICS.FORUM_ID GROUP BY FORUM. NAME, FORUM,
    > DESCRIPT,
    > FORUM.CREATION_DT A RESULTING RECORDSET SAMPLE FOR THIS QUERY COULD BE AS
    > FOLLOWS NAME DESCRIPT CREATION_DT TOPIC_CNT science
    > science stuff 1/1/2001 5 politics
    > worse
    > stuff 2/2/2002 3 the topic cnt field
    > represents how
    > many topic there are in each forum
    >

    hoohim 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