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

  1. #1

    Default If......Else

    A SQL Server 7.0 database table named Table1 has 3 fields - ID (which
    is unique & the primary key), Quantity & Amount. There is another
    database table named Table2 which has 2 fields - ID & Taxable (records
    under the Taxable column can have only 2 values - Yes or No). Table1 &
    Table2 can be JOINed using the primary key ID. Now I have to display
    these records in a web page in a HTML table in this way:

    --------------------------------------
    ID Charge Taxable
    ---------------------------------------
    1 500.00 No
    2 400.00 Yes
    3 300.00 No
    4 200.00 Yes
    ----------------------------------------


    Charge is the product of Table1.Quantity*Table1.Amount. The SQL query
    to retrieve the records is this:

    SELECT Table1.ID,(Table1.Quantity*Table1.Amount) AS
    'Charge',Table2.Taxable FROM Table1 INNER JOIN Table2 ON
    Table1.ID=Table2.ID

    Apart from the HTML table displayed above, the web page should also
    show the sum of charges which is taxable & also the sum of charges
    which is not taxable. For e.g. using the above 4 records, the sum of
    charges which is non-taxable is 500+300=800 (since Taxable is No for
    the charges 500 & 300) where as the sum of charges which is taxable is
    400+200=600 (since Taxable is Yes for the charges 400 & 200). Now how
    do I find the 2 sums i.e. sum of charges which is taxable & sum of
    charges which is non-taxable?

    Thanks,

    Arpan
    Arpan Guest

  2. #2

    Default Re: If......Else

    there are a few ways of accomplishing what you ask

    you could create a couple more recordsets to return the totals you require,
    or you could add some code to your page, as below

    there are lots of clever folks on here, so someone will most likely provide
    a better solution than this,
    but here's a basic method (ASP/VB), i've added the HTML of a table to
    indicate where the code would be located.
    hope this helps

    <table>
    <%
    not_tax = 0
    tax = 0

    while not recordset.eof

    if recordset("taxable") = "No" then
    not_tax = not_tax + recordset("charge")
    else
    tax = tax + recordset("charge")
    end if %>
    <tr><td>...</td></tr>

    <% recordset.movenext
    wend %>
    </table>

    <% response.write "non-taxable = " & not_tax
    response.write "taxable = " & tax %>

    Jason

    "Arpan" <arpan_de@hotmail.com> wrote in message
    news:74df0ab.0307181446.591882d3@posting.google.co m...
    > A SQL Server 7.0 database table named Table1 has 3 fields - ID (which
    > is unique & the primary key), Quantity & Amount. There is another
    > database table named Table2 which has 2 fields - ID & Taxable (records
    > under the Taxable column can have only 2 values - Yes or No). Table1 &
    > Table2 can be JOINed using the primary key ID. Now I have to display
    > these records in a web page in a HTML table in this way:
    >
    > --------------------------------------
    > ID Charge Taxable
    > ---------------------------------------
    > 1 500.00 No
    > 2 400.00 Yes
    > 3 300.00 No
    > 4 200.00 Yes
    > ----------------------------------------
    >
    >
    > Charge is the product of Table1.Quantity*Table1.Amount. The SQL query
    > to retrieve the records is this:
    >
    > SELECT Table1.ID,(Table1.Quantity*Table1.Amount) AS
    > 'Charge',Table2.Taxable FROM Table1 INNER JOIN Table2 ON
    > Table1.ID=Table2.ID
    >
    > Apart from the HTML table displayed above, the web page should also
    > show the sum of charges which is taxable & also the sum of charges
    > which is not taxable. For e.g. using the above 4 records, the sum of
    > charges which is non-taxable is 500+300=800 (since Taxable is No for
    > the charges 500 & 300) where as the sum of charges which is taxable is
    > 400+200=600 (since Taxable is Yes for the charges 400 & 200). Now how
    > do I find the 2 sums i.e. sum of charges which is taxable & sum of
    > charges which is non-taxable?
    >
    > Thanks,
    >
    > Arpan

    jason kennedy 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