Counting problem

  • I am trying to create a stored procedure that counts a certain record in a couple different ways. Here is the first count.

    CREATE PROCEDURE smtptest

    AS

    Select count([cs-username]) text

    from smtp

    where [cs-username] = 'mcmasa02' and [cs-method] = 'data' and [cs-bytes] > 200 and [cs-bytes] < 2000

    GO

    This outputs a table with one column named text and the count.

    I want put in the same procedure another count on the field [cs-username]

    where [cs-username] = 'mcmasa02' and [cs-method] = 'data' and [cs-bytes] > 10000 and [cs-bytes] < 90000

    I want the field to be named "photo"

    What I am trying to get for a return table is the column Text and the column Photo with there correseponding count values. If I can do this then I can add more count fields such as "video" I just can't figure out how to get the stored procedure to count the [cs-username] field more than one time with different conditions.

  • Couple options. One is that you can return multiple recordsets - each select will return one - in ADO take a look at the nextrecordset method. Another would be to use output parameters, where param1 is item1, param2 is item2, etc. Another would be to union the results of your different count queries into one result set (or insert them into a temp table and just select all back from it).

    Andy

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply