Putting query to good use.

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Putting query to good use.

    Hey folks, hope you all had a good weekend. Here's this mornings
    dilema for me.

    I have my query, which when ran in Query Analyzer, gives me back nice
    neat little rows with the percentages.

    "SELECT fit, count(*) * 100.00/ (select count (*) from internal) as
    [Percent] FROM internal GROUP by fit"

    gives me...

    fit Percent
    --------------------------------------------------
    ----------------------------
    Agree 20.000000000000
    Disagree 20.000000000000
    Neither 20.000000000000
    StronglyAgree 40.000000000000

    (4 row(s) affected)

    I've constructed my recordset in asp, with the above query. My
    question is, how do i structure an ASP page to show me the results?
    Any pointers in the general direction would be much appreciated.

    Thanks for your time gurus!
    nathan Guest

  2. Similar Questions and Discussions

    1. Xcart no good, support no good, need good shopping cart!!!
      I need a good quality php shopping cart to port to my site, allowing software downloads and book sales. Integrating ease is really important and...
  3. #2

    Default Re: Putting query to good use.

    <table>
    <%
    Dim oADO, oRS, sSQL

    sSQL = "SELECT fit, count(*) * 100.00/ (select count (*) from internal) as
    [Percent] FROM internal GROUP by fit"
    Set oADO = Server.CreateObject("ADODB.Connection")
    oADO.Open YourConnectionString
    Set oRS = oADO.Execute(sSQL)

    Do While Not oRS.EOF
    %>
    <tr>
    <td><%=oRS.Fields.Item(0).Value%></td>
    <td><%=FormatNumber(oRS.Fields.Item(0).Value, 2, -1)%>%</td>
    </tr>
    <%
    oRS.MoveNext
    Loop
    oRS.Close : Set oRS = Nothing
    oADO.Close : Set oADO = Nothing
    %>

    After you get that working, take a look at these articles though.

    [url]http://www.aspfaq.com/2073[/url] (Part about counting)
    [url]http://www.aspfaq.com/2467[/url]

    Also, you could/should make that a stored procedure on your server.

    Ray at work




    "nathan" <n4th4n@hushmail.com> wrote in message
    news:908008f8.0310060941.52fdcb77@posting.google.c om...
    > Hey folks, hope you all had a good weekend. Here's this mornings
    > dilema for me.
    >
    > I have my query, which when ran in Query Analyzer, gives me back nice
    > neat little rows with the percentages.
    >
    > "SELECT fit, count(*) * 100.00/ (select count (*) from internal) as
    > [Percent] FROM internal GROUP by fit"
    >
    > gives me...
    >
    > fit Percent
    > --------------------------------------------------
    > ----------------------------
    > Agree 20.000000000000
    > Disagree 20.000000000000
    > Neither 20.000000000000
    > StronglyAgree 40.000000000000
    >
    > (4 row(s) affected)
    >
    > I've constructed my recordset in asp, with the above query. My
    > question is, how do i structure an ASP page to show me the results?
    > Any pointers in the general direction would be much appreciated.
    >
    > Thanks for your time gurus!

    Ray at Guest

  4. #3

    Default Re: Putting query to good use.

    Actually, I would prefer:

    <%
    Dim oADO, oRS, sSQL
    Dim sHTML

    sHTML = "<table><tr><td>"
    sSQL = "SELECT fit, count(*) * 100.00/ (select count (*) from internal) as
    [Percent] FROM internal GROUP by fit"
    Set oADO = Server.CreateObject("ADODB.Connection")
    oADO.Open YourConnectionString
    Set oRS = oADO.Execute(sSQL)
    sHTML = sHTML & oRS.GetString(,,"</td><td>","</td></tr><tr><td>")
    oRS.close
    set oRS = nothing
    oADO.close
    set oADO = nothing
    sHTML = left(sHTML,len(sHTML) - 8) & "</table>"
    %>
    <HTML><HEAD></HEAD><BODY>
    <%=sHTML%>
    </BODY></HTML>

    HTH,
    Bob Barrows



    Ray at <%=sLocation%> wrote:
    > <table>
    > <%
    > Dim oADO, oRS, sSQL
    >
    > sSQL = "SELECT fit, count(*) * 100.00/ (select count (*) from
    > internal) as [Percent] FROM internal GROUP by fit"
    > Set oADO = Server.CreateObject("ADODB.Connection")
    > oADO.Open YourConnectionString
    > Set oRS = oADO.Execute(sSQL)
    >
    > Do While Not oRS.EOF
    > %>
    > <tr>
    > <td><%=oRS.Fields.Item(0).Value%></td>
    > <td><%=FormatNumber(oRS.Fields.Item(0).Value, 2, -1)%>%</td>
    > </tr>
    > <%
    > oRS.MoveNext
    > Loop
    > oRS.Close : Set oRS = Nothing
    > oADO.Close : Set oADO = Nothing
    > %>
    >
    > After you get that working, take a look at these articles though.
    >
    > [url]http://www.aspfaq.com/2073[/url] (Part about counting)
    > [url]http://www.aspfaq.com/2467[/url]
    >
    > Also, you could/should make that a stored procedure on your server.
    >
    > Ray at work
    >
    >
    >
    >
    > "nathan" <n4th4n@hushmail.com> wrote in message
    > news:908008f8.0310060941.52fdcb77@posting.google.c om...
    >> Hey folks, hope you all had a good weekend. Here's this mornings
    >> dilema for me.
    >>
    >> I have my query, which when ran in Query Analyzer, gives me back nice
    >> neat little rows with the percentages.
    >>
    >> "SELECT fit, count(*) * 100.00/ (select count (*) from internal) as
    >> [Percent] FROM internal GROUP by fit"
    >>
    >> gives me...
    >>
    >> fit Percent
    >> --------------------------------------------------
    >> ----------------------------
    >> Agree 20.000000000000
    >> Disagree 20.000000000000
    >> Neither 20.000000000000
    >> StronglyAgree 40.000000000000
    >>
    >> (4 row(s) affected)
    >>
    >> I've constructed my recordset in asp, with the above query. My
    >> question is, how do i structure an ASP page to show me the results?
    >> Any pointers in the general direction would be much appreciated.
    >>
    >> Thanks for your time gurus!

    Bob Barrows Guest

  5. #4

    Default Re: Putting query to good use.

    Oops - that was in one of the links - guess I just wasted a few minutes...
    Bob Barrows wrote:
    > Actually, I would prefer:
    >
    <snip>


    Bob Barrows Guest

  6. #5

    Default Re: Putting query to good use.

    Hey, come on now, I provided the links for that method. :] And I thought
    you'd prefer a SP.

    Ray at work

    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:%23VltMUDjDHA.2644@TK2MSFTNGP10.phx.gbl...
    > Actually, I would prefer:
    >
    > <%
    > Dim oADO, oRS, sSQL
    > Dim sHTML
    >
    > sHTML = "<table><tr><td>"
    > sSQL = "SELECT fit, count(*) * 100.00/ (select count (*) from internal) as
    > [Percent] FROM internal GROUP by fit"
    > Set oADO = Server.CreateObject("ADODB.Connection")
    > oADO.Open YourConnectionString
    > Set oRS = oADO.Execute(sSQL)
    > sHTML = sHTML & oRS.GetString(,,"</td><td>","</td></tr><tr><td>")
    > oRS.close
    > set oRS = nothing
    > oADO.close
    > set oADO = nothing
    > sHTML = left(sHTML,len(sHTML) - 8) & "</table>"
    > %>
    > <HTML><HEAD></HEAD><BODY>
    > <%=sHTML%>
    > </BODY></HTML>
    >
    > HTH,
    > Bob Barrows
    >
    >

    Ray at Guest

  7. #6

    Default Re: Putting query to good use.

    Ray at <%=sLocation%> wrote:
    > ...And I
    > thought you'd prefer a SP.
    >
    Absolutely :-)


    Bob Barrows Guest

  8. #7

    Default Re: Putting query to good use.

    > Also, you could/should make that a stored procedure on your server.

    You can see an incomplete article about that in [url]http://www.aspfaq.com/2201[/url]


    Aaron Bertrand - MVP Guest

  9. #8

    Default Re: Putting query to good use.

    Thanks for the help gentlemen, worked great, and thanks for the articles.
    nathan 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