retrieving a summed value from a recordset.. very odd one!

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

  1. #1

    Default retrieving a summed value from a recordset.. very odd one!

    I have a simple sql query which contains a sum function, this is then given
    a column name.

    If i run it in query analyser i get a correct result.
    Yet if i do a response.write rec("columnname") i get no result

    There is no asp error saying cannot find item .... etc.. so i know it is
    finding the item - it just has no value in there.
    Anyone ever seen this?

    query as below:
    Select S.Name, I.start,I.nights, S.City, R.Name,
    sum(CASE WHEN A.Occ = 4 then 4 * S4
    WHEN A.OCC = 3 then 3 * S3
    WHEN A.OCC = 2 then 2 * S2
    WHEN A.OCC = 1 then S1
    END) TotalC
    from itinerary I
    left outer join allocation A on I.ID = A.Itineraryid and A.Occ > 0
    inner join supplier S on I.SupplierID = S.ID
    inner join region r on r.id=s.cid
    where quoteid =91 And I.Qty > 0
    group by I.QuoteID, S.ID, S.Name, S.City, R.Name, I.start, I.nights
    order by S.Name

    output asp as below:

    rsprop.open sql, Con
    ...
    ...

    <snip>
    ...

    <%=rsprop("TotalC")%>

    All other values returned display fine on my page.


    Pete Guest

  2. Similar Questions and Discussions

    1. Retrieving Images from Recordset
      Sorry, ive gone through all the posts, but im unable to find the answer... In a repeat region table i (based on users2 recordset that collects id...
    2. RecordSet.Move or RecordSet.AbsolutePosition??
      Hi, I'm trying to use either one of these methods to position the cursor in a specific position inside a recordset, but neither one seems to...
    3. Retrieving GUID from DB2 UDB
      Bill Homan <member35043@dbforums.com> wrote in message news:<3203554.1060104571@dbforums.com>... What is actually in the CHAR(16) FOR BIT DATA...
    4. retrieving of numbers
      hello sir i have a text file which i have linked to access ,by using external data option in file menu and the text file is made as a table. ...
    5. retrieving identity
      It's better to use SCOPE_INDENTITY( ) @@IDENTITY can give a bad answer in some situations. "Kevin Spencer" <kevin@SPAMMERSSUCKtakempis.com> a...
  3. #2

    Default Re: retrieving a summed value from a recordset.. very odd one!

    Try changing your query to:

    SUM(...) AS TotalC
    TotalC = SUM(...)

    or refer to rs(5) instead of rs("TotalC")

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




    "Pete" <pbarnsley@discovertravelandtours.com> wrote in message
    news:3fcf518b$1@news.star.co.uk...
    > I have a simple sql query which contains a sum function, this is then
    given
    > a column name.
    >
    > If i run it in query analyser i get a correct result.
    > Yet if i do a response.write rec("columnname") i get no result
    >
    > There is no asp error saying cannot find item .... etc.. so i know it is
    > finding the item - it just has no value in there.
    > Anyone ever seen this?
    >
    > query as below:
    > Select S.Name, I.start,I.nights, S.City, R.Name,
    > sum(CASE WHEN A.Occ = 4 then 4 * S4
    > WHEN A.OCC = 3 then 3 * S3
    > WHEN A.OCC = 2 then 2 * S2
    > WHEN A.OCC = 1 then S1
    > END) TotalC
    > from itinerary I
    > left outer join allocation A on I.ID = A.Itineraryid and A.Occ > 0
    > inner join supplier S on I.SupplierID = S.ID
    > inner join region r on r.id=s.cid
    > where quoteid =91 And I.Qty > 0
    > group by I.QuoteID, S.ID, S.Name, S.City, R.Name, I.start, I.nights
    > order by S.Name
    >
    > output asp as below:
    >
    > rsprop.open sql, Con
    > ..
    > ..
    >
    > <snip>
    > ..
    >
    > <%=rsprop("TotalC")%>
    >
    > All other values returned display fine on my page.
    >
    >

    Aaron Bertrand - MVP Guest

  4. #3

    Default Re: retrieving a summed value from a recordset.. very odd one!

    Heh...

    no it was much simpler than that, my recordset on the asp page was using a
    different value than the query analyser which was wrong... oops!

    sorry to waste time!.
    "Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
    news:O1l4lFouDHA.3536@tk2msftngp13.phx.gbl...
    > Try changing your query to:
    >
    > SUM(...) AS TotalC
    > TotalC = SUM(...)
    >
    > or refer to rs(5) instead of rs("TotalC")
    >
    > --
    > Aaron Bertrand
    > SQL Server MVP
    > [url]http://www.aspfaq.com/[/url]
    >
    >
    >
    >
    > "Pete" <pbarnsley@discovertravelandtours.com> wrote in message
    > news:3fcf518b$1@news.star.co.uk...
    > > I have a simple sql query which contains a sum function, this is then
    > given
    > > a column name.
    > >
    > > If i run it in query analyser i get a correct result.
    > > Yet if i do a response.write rec("columnname") i get no result
    > >
    > > There is no asp error saying cannot find item .... etc.. so i know it is
    > > finding the item - it just has no value in there.
    > > Anyone ever seen this?
    > >
    > > query as below:
    > > Select S.Name, I.start,I.nights, S.City, R.Name,
    > > sum(CASE WHEN A.Occ = 4 then 4 * S4
    > > WHEN A.OCC = 3 then 3 * S3
    > > WHEN A.OCC = 2 then 2 * S2
    > > WHEN A.OCC = 1 then S1
    > > END) TotalC
    > > from itinerary I
    > > left outer join allocation A on I.ID = A.Itineraryid and A.Occ > 0
    > > inner join supplier S on I.SupplierID = S.ID
    > > inner join region r on r.id=s.cid
    > > where quoteid =91 And I.Qty > 0
    > > group by I.QuoteID, S.ID, S.Name, S.City, R.Name, I.start, I.nights
    > > order by S.Name
    > >
    > > output asp as below:
    > >
    > > rsprop.open sql, Con
    > > ..
    > > ..
    > >
    > > <snip>
    > > ..
    > >
    > > <%=rsprop("TotalC")%>
    > >
    > > All other values returned display fine on my page.
    > >
    > >
    >
    >

    Pete 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