ASP, using SQL COUNT as a condition in IF ELSE statement

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

  1. #1

    Default ASP, using SQL COUNT as a condition in IF ELSE statement

    I am trying to do a simple "less than" conditional statement, and hitting a
    brick wall if I use a database element with it.

    This DOES work:
    <%
    if Request.QueryString("PC") < 10 then Response.Write("less than ten") else
    Response.Write("more than or equal to ten") End if
    %>


    This DOES NOT work:
    <%
    if Request.QueryString("PC") < Record.Fields.Item("count(*)").Value then
    Response.Write("less than COUNT") else Response.Write("less than or equal to
    count") End if
    %>

    The only difference is that in the first example a number is used as the
    condition. in the second example, I have counted the number of rows in a
    table, and I want to use that number as the condition. The SQL select is:
    SELECT count(*), EnquiryDate
    FROM lfmasterleads.partner_enquiries
    WHERE EnquiryDate = CURRENT_DATE() GROUP BY EnquiryDate

    Any help greatly appreciated!

    Darren.


    Gary Guest

  2. Similar Questions and Discussions

    1. condition
      hey jan... i do it like this: function existRec (name) { for (i=0; i<recs.length; i++) { if (recs == name) { return true; } } return false;...
    2. ?: condition
      eh, probably dumm question but why is asking to return a value not working here? for (var i=0;i< x.length; i++) { x ? : return true : null; }
    3. complex condition
      I know there must be a way to do the following: if (($foobar > 3) || ($foo="t" && $bar = "b")) {print "yup"} Of course this is wrong, but what...
    4. DB2 upgrade condition
      Hi all, i've got db2 udb enterprise server v. 7.1 .... it's possible to upgrade to 7.2 or 8.1 ? It's free? Thanks Stefano
    5. Trying to create a condition statement in
      Ampersand. && My mistake was that I did not put the word 'javascript:' in front of the script. mybutton.attributes.add ( "javascript:if...
  3. #2

    Default Re: ASP, using SQL COUNT as a condition in IF ELSE statement

    There is no such column as COUNT(*). See [url]http://www.aspfaq.com/2159[/url]

    --
    Aaron Bertrand
    SQL Server MVP
    [url]http://www.aspfaq.com/[/url]




    "Gary" <sorry@nocando.com> wrote in message
    news:6ibYb.564$Ih4.6389862@news-text.cableinet.net...
    > I am trying to do a simple "less than" conditional statement, and hitting
    a
    > brick wall if I use a database element with it.
    >
    > This DOES work:
    > <%
    > if Request.QueryString("PC") < 10 then Response.Write("less than ten")
    else
    > Response.Write("more than or equal to ten") End if
    > %>
    >
    >
    > This DOES NOT work:
    > <%
    > if Request.QueryString("PC") < Record.Fields.Item("count(*)").Value then
    > Response.Write("less than COUNT") else Response.Write("less than or equal
    to
    > count") End if
    > %>
    >
    > The only difference is that in the first example a number is used as the
    > condition. in the second example, I have counted the number of rows in a
    > table, and I want to use that number as the condition. The SQL select is:
    > SELECT count(*), EnquiryDate
    > FROM lfmasterleads.partner_enquiries
    > WHERE EnquiryDate = CURRENT_DATE() GROUP BY EnquiryDate
    >
    > Any help greatly appreciated!
    >
    > Darren.
    >
    >

    Aaron Bertrand - MVP Guest

  4. #3

    Default Re: ASP, using SQL COUNT as a condition in IF ELSE statement


    "Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
    news:enbI4tN9DHA.1472@TK2MSFTNGP11.phx.gbl...
    > There is no such column as COUNT(*). See [url]http://www.aspfaq.com/2159[/url]


    Seems to work for me?
    Gary


    Gary Guest

  5. #4

    Default Re: ASP, using SQL COUNT as a condition in IF ELSE statement

    > Seems to work for me?

    Maybe I should rephrase. COUNT(*) is not a column, it is an aggregate. You
    cannot refer directly to an aggregate, as the article (and your own "DOES
    NOT work" experience) has shown you. You need to define an alias or use the
    ordinal number.

    --
    Aaron Bertrand
    SQL Server MVP
    [url]http://www.aspfaq.com/[/url]


    Aaron Bertrand - MVP Guest

  6. #5

    Default Re: ASP, using SQL COUNT as a condition in IF ELSE statement

    <<
    I am trying to do a simple "less than" conditional statement, and
    hitting a
    brick wall if I use a database element with it.

    This DOES work:
    <%
    if Request.QueryString("PC") < 10 then Response.Write("less than ten")
    else
    Response.Write("more than or equal to ten") End if
    %>


    This DOES NOT work:
    <%
    if Request.QueryString("PC") < Record.Fields.Item("count(*)").Value then
    Response.Write("less than COUNT") else Response.Write("less than or
    equal to
    count") End if
    %>

    The only difference is that in the first example a number is used as the
    condition. in the second example, I have counted the number of rows in a
    table, and I want to use that number as the condition. The SQL select
    is:
    SELECT count(*), EnquiryDate
    FROM lfmasterleads.partner_enquiries
    WHERE EnquiryDate = CURRENT_DATE() GROUP BY EnquiryDate

    Any help greatly appreciated!

    Darren.
    >>
    Perhaps change:
    SELECT count(*), EnquiryDate

    To be this instead:
    SELECT count(*) AS RecCount, EnquiryDate

    And then on the first record use the value of objRS("RecCount").

    Best regards,
    J. Paul Schmidt, Freelance ASP Web Developer
    [url]http://www.Bullschmidt.com[/url]
    ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Bullschmidt 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