Professional Web Applications Themes

Total Rows and count of specific instance in one read - ASP Database

Is it possible to get the total number of rows and specify where clause in the same stored procedure. For instance, I am trying to get the the total number of widgets that = 'Toys' so I can get a percentage of widgets = 'Toys' for the widget category. Is it possible?...

  1. #1

    Default Total Rows and count of specific instance in one read

    Is it possible to get the total number of rows and specify
    where clause in the same stored procedure.

    For instance, I am trying to get the the total number of
    widgets that = 'Toys' so I can get a percentage of widgets
    = 'Toys' for the widget category.

    Is it possible?
    Mike Guest

  2. #2

    Default Re: Total Rows and count of specific instance in one read

    Sorry,
    sql server 2000. What does ABS do?
    >-----Original Message-----
    >"Mike" <anonymousdiscussions.microsoft.com> wrote in
    message
    >news:b72901c43784$c4281b30$a601280aphx.gbl...
    >> Is it possible to get the total number of rows and
    specify
    >> where clause in the same stored procedure.
    >>
    >> For instance, I am trying to get the the total number of
    >> widgets that = 'Toys' so I can get a percentage of
    widgets
    >> = 'Toys' for the widget category.
    >>
    >> Is it possible?
    >
    >Database? Version? DDL? Sample Data? Desired Output?
    >[url]http://aspfaq.com/etiquette.asp?id=5006[/url]
    >[url]http://aspfaq.com/etiquette.asp?id=5009[/url]
    >
    >The query would look something like this. You will need
    to modify it to
    >reflect your database structure since I have no idea what
    it looks like.
    >
    >SELECT
    >ABS(SUM(W.CategoryName = 'Toys'))/COUNT(*) AS
    ToysPercentage
    >FROM
    >Widgets AS W
    >
    >HTH
    >-Chris Hohmann
    >
    >
    >.
    >
    Mike Guest

  3. #3

    Default Re: Total Rows and count of specific instance in one read

    "Mike" <anonymousdiscussions.microsoft.com> wrote in message
    news:b72901c43784$c4281b30$a601280aphx.gbl...
    > Is it possible to get the total number of rows and specify
    > where clause in the same stored procedure.
    >
    > For instance, I am trying to get the the total number of
    > widgets that = 'Toys' so I can get a percentage of widgets
    > = 'Toys' for the widget category.
    >
    > Is it possible?
    Database? Version? DDL? Sample Data? Desired Output?
    [url]http://aspfaq.com/etiquette.asp?id=5006[/url]
    [url]http://aspfaq.com/etiquette.asp?id=5009[/url]

    The query would look something like this. You will need to modify it to
    reflect your database structure since I have no idea what it looks like.

    SELECT
    ABS(SUM(W.CategoryName = 'Toys'))/COUNT(*) AS ToysPercentage
    FROM
    Widgets AS W

    HTH
    -Chris Hohmann


    Chris Hohmann Guest

  4. #4

    Default Re: Total Rows and count of specific instance in one read

    "Mike" <anonymousdiscussions.microsoft.com> wrote in message
    news:b77801c43788$1f3e40f0$a001280aphx.gbl...
    > Sorry,
    > sql server 2000. What does ABS do?
    No problem. ABS is the Absolute Value function. In some database
    environments booleans expressions like "W.CategoryName='Toys'" evaluates
    to -1 for TRUE and 0 for FALSE.I used ABS to make sure you didn't end up
    with a negative percentage. In SQL Server 2000, booleans are treated
    differently. The query would look something like this:

    SELECT
    SUM(CASE W.CategoryName WHEN 'Toys' THEN 1 ELSE 0 END)/CAST(COUNT(*) AS
    DECIMAL(5,2)) AS ToysPercentage
    FROM
    Widgets AS W

    Again, you will need to modify the above to reflect your particular database
    structure.

    HTH
    -Chris Hohmann


    Chris Hohmann Guest

Similar Threads

  1. Getting Total Item Count in Paging Datagrid
    By jason smith in forum ASP.NET Data Grid Control
    Replies: 6
    Last Post: October 28th, 07:26 PM
  2. Verity total doent count
    By Tom Jordahl in forum Coldfusion Server Administration
    Replies: 0
    Last Post: May 17th, 02:27 PM
  3. Counting the total instance in an array.
    By webhead_1 in forum Macromedia ColdFusion
    Replies: 0
    Last Post: February 23rd, 09:41 PM
  4. total record count in datagrid
    By DC Gringo in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: March 4th, 08:32 PM
  5. Any serverscript to count total images in a folder
    By sraval in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: February 10th, 05:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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