Select Qry: Differing results via Access & ADO (& SQL Server)

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

  1. #1

    Default Select Qry: Differing results via Access & ADO (& SQL Server)

    I have a query which produces different results in the Access query builder
    and in an ASP page (via ADO)

    An example of the query is:
    ----------------------------------------------------------
    Select 'Ranked' as Source, H.HotelName, H.TelNo, H.URL, H.Location,
    H.HotelID, Rank
    from (Hotels H Inner Join PrefHotels P on H.HotelID = P.HotelID)
    Inner Join Locations L on P.LocID = L.LocID
    where Rank is not null and Rank > 0 and L.LocID=2

    Union

    Select 'Unranked' as Source, H.HotelName, H.TelNo, H.URL, H.Location,
    H.HotelID, Rank
    from (Hotels H Inner Join PrefHotels P on H.HotelID = P.HotelID)
    Inner Join Locations L on P.LocID = L.LocID
    where (Rank is Null or Rank = 0) and L.LocID=2

    Order By Source, Rank
    ----------------------------------------------------------

    In Access, I get the following results

    Ranked, Hotel1, [other fields], 1
    Ranked, Hotel2, [other fields], 2
    Ranked, Hotel3, [other fields], 3
    Unranked, Hotel4, [other fields], 0
    Unranked, Hotel4, [other fields], 0
    Unranked, Hotel4, [other fields], 0
    etc...

    In my ASP Page I get these results:

    Unranked, Hotel1, [other fields],
    Unranked, Hotel2, [other fields],
    Unranked, Hotel3, [other fields],
    Unranked, Hotel4, [other fields],
    Unranked, Hotel4, [other fields],
    Unranked, Hotel4, [other fields],
    etc...

    I've imported the Access DB to SQL Server, and in Query Analyser and in the
    ASP page I get the right result:
    Ranked, Hotel1, [other fields], 1
    Ranked, Hotel2, [other fields], 2
    Ranked, Hotel3, [other fields], 3
    Unranked, Hotel4, [other fields], 0
    Unranked, Hotel4, [other fields], 0
    Unranked, Hotel4, [other fields], 0
    etc...

    (ie Same as in Access)

    I'm assuming that if Access itself doesnt object to the SQL, it must be
    right. Therefore, the problem lies with ADO and the Access OLEDB drivers...

    Any ideas?

    Chris


    CJM Guest

  2. Similar Questions and Discussions

    1. Select from function for part of column results
      Hi Oisin On 03/02/05, Oisin Glynn (me@oisinglynn.com) wrote: This works great for a function returning a single column. I'm not sure how to do...
    2. Using PHP to Print SELECT Results - Incomplete Data Returned
      So this little problem has stumped me for close to an hour, and I know it's something easy... I'm using PHP to select field values from a record...
    3. Subform data select on access/ sql server database
      Hi, I have a client/server accessxp/sql server 2000 database. On the main form there is a subform that uses a stored procedure to collect a set...
    4. DB2 Select - how to return a range of results
      Hi, Here is some SQL from MS SQL 2000: select top 5 * from (select top 5 * from (select top 25 code, name, address from contacts where name...
    5. Replace character in SELECT results
      Hi, I have a SELECT statement of multiple columns from joined tables. One of the columns is an address field. It is one field that contains the...
  3. #2

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    So you aren't seeing [Rank] from your query in your ASP pages? What code
    are you using to display the recordset values?

    --

    Ray at home
    Microsoft ASP MVP


    "CJM" <cjmwork@yahoo.co.uk> wrote in message
    news:%234$MKx5%23DHA.3668@TK2MSFTNGP09.phx.gbl...
    > I have a query which produces different results in the Access query
    builder
    > and in an ASP page (via ADO)
    >
    > An example of the query is:
    > ----------------------------------------------------------
    > Select 'Ranked' as Source, H.HotelName, H.TelNo, H.URL, H.Location,
    > H.HotelID, Rank
    > from (Hotels H Inner Join PrefHotels P on H.HotelID = P.HotelID)
    > Inner Join Locations L on P.LocID = L.LocID
    > where Rank is not null and Rank > 0 and L.LocID=2
    >
    > Union
    >
    > Select 'Unranked' as Source, H.HotelName, H.TelNo, H.URL, H.Location,
    > H.HotelID, Rank
    > from (Hotels H Inner Join PrefHotels P on H.HotelID = P.HotelID)
    > Inner Join Locations L on P.LocID = L.LocID
    > where (Rank is Null or Rank = 0) and L.LocID=2
    >
    > Order By Source, Rank
    > ----------------------------------------------------------
    >
    > In Access, I get the following results
    >
    > Ranked, Hotel1, [other fields], 1
    > Ranked, Hotel2, [other fields], 2
    > Ranked, Hotel3, [other fields], 3
    > Unranked, Hotel4, [other fields], 0
    > Unranked, Hotel4, [other fields], 0
    > Unranked, Hotel4, [other fields], 0
    > etc...
    >
    > In my ASP Page I get these results:
    >
    > Unranked, Hotel1, [other fields],
    > Unranked, Hotel2, [other fields],
    > Unranked, Hotel3, [other fields],
    > Unranked, Hotel4, [other fields],
    > Unranked, Hotel4, [other fields],
    > Unranked, Hotel4, [other fields],
    > etc...
    >
    > I've imported the Access DB to SQL Server, and in Query Analyser and in
    the
    > ASP page I get the right result:
    > Ranked, Hotel1, [other fields], 1
    > Ranked, Hotel2, [other fields], 2
    > Ranked, Hotel3, [other fields], 3
    > Unranked, Hotel4, [other fields], 0
    > Unranked, Hotel4, [other fields], 0
    > Unranked, Hotel4, [other fields], 0
    > etc...
    >
    > (ie Same as in Access)
    >
    > I'm assuming that if Access itself doesnt object to the SQL, it must be
    > right. Therefore, the problem lies with ADO and the Access OLEDB
    drivers...
    >
    > Any ideas?
    >
    > Chris
    >
    >

    Ray at Guest

  4. #3

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    Ray,

    I'll spare you the full table structure, but in the debugging process, I
    added a line like this straight after the oConn.Execute:

    With rs
    Response.Write .fields(0) & "," & .fields(1) & "," & ....... &
    ..fields(7)
    End With

    And obviously it came out as:

    Unranked, Hotelname, ...other details... , <= No Rank
    value

    Chris



    "Ray at <%=sLocation%> [MVP]" <Too many private support requests - Ask for
    it if needed> wrote in message
    news:%23y3Vn55%23DHA.2636@TK2MSFTNGP09.phx.gbl...
    > So you aren't seeing [Rank] from your query in your ASP pages? What code
    > are you using to display the recordset values?
    >
    > --
    >
    > Ray at home
    > Microsoft ASP MVP
    >
    >

    CJM Guest

  5. #4

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    Could you show us what you get with

    response.write rs.GetString(2,," | ", "<BR>")

    Bob Barrows
    CJM wrote:
    > Ray,
    >
    > I'll spare you the full table structure, but in the debugging
    > process, I added a line like this straight after the oConn.Execute:
    >
    > With rs
    > Response.Write .fields(0) & "," & .fields(1) & "," & ....... &
    > .fields(7)
    > End With
    >
    > And obviously it came out as:
    >
    > Unranked, Hotelname, ...other details... , <= No
    > Rank value
    >
    > Chris
    >
    >
    >
    > "Ray at <%=sLocation%> [MVP]" <Too many private support requests -
    > Ask for it if needed> wrote in message
    > news:%23y3Vn55%23DHA.2636@TK2MSFTNGP09.phx.gbl...
    >> So you aren't seeing [Rank] from your query in your ASP pages? What
    >> code are you using to display the recordset values?
    >>
    >> --
    >>
    >> Ray at home
    >> Microsoft ASP MVP


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  6. #5

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    If you rearrange the order in which you select the columns, does it display
    differently? Eg.

    Select 'Ranked' as Source,Rank, H.HotelName, H.TelNo, H.URL, H.Location,
    H.HotelID
    from (Hotels H Inner Join PrefHotels P on H.HotelID = P.HotelID)
    Inner Join Locations L on P.LocID = L.LocID
    where Rank is not null and Rank > 0 and L.LocID=2

    Union

    Select 'Unranked' as Source,Rank, H.HotelName, H.TelNo, H.URL, H.Location,
    H.HotelID
    from (Hotels H Inner Join PrefHotels P on H.HotelID = P.HotelID)
    Inner Join Locations L on P.LocID = L.LocID
    where (Rank is Null or Rank = 0) and L.LocID=2

    Order By Source, Rank

    Ray at work

    "CJM" <cjmwork@yahoo.co.uk> wrote in message
    news:ORl5PF6%23DHA.2524@tk2msftngp13.phx.gbl...
    > Ray,
    >
    > I'll spare you the full table structure, but in the debugging process, I
    > added a line like this straight after the oConn.Execute:
    >
    > With rs
    > Response.Write .fields(0) & "," & .fields(1) & "," & ....... &
    > .fields(7)
    > End With
    >
    > And obviously it came out as:
    >
    > Unranked, Hotelname, ...other details... , <= No Rank
    > value
    >
    > Chris
    >
    >
    >
    > "Ray at <%=sLocation%> [MVP]" <Too many private support requests - Ask for
    > it if needed> wrote in message
    > news:%23y3Vn55%23DHA.2636@TK2MSFTNGP09.phx.gbl...
    > > So you aren't seeing [Rank] from your query in your ASP pages? What
    code
    > > are you using to display the recordset values?
    > >
    > > --
    > >
    > > Ray at home
    > > Microsoft ASP MVP
    > >
    > >
    >
    >

    Ray at Guest

  7. #6

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    Well you are onto something here Bob...

    I seem to be getting the right response:

    Ranked | Hotelname | TelNo | | Location | 4 | 1
    etc...

    So by this we can determine the recordset is correct... I'm really confused
    now!

    Here's the next code snippet:
    ------------------------------------------------------
    Set rsInfo = oConn.Execute (sSQL, iAffected, adCmdText)

    With rsInfo

    %>
    <thead>
    <tr class="Hotel">
    <th>Rank</th>
    <th>Hotel</th>
    <th>Location</th>
    <th>Tel No.</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    </tr>
    </thead>
    <%
    Do while not .EOF
    sURL =.Fields("URL")
    If Left(sURL,7)<>"http://" Then
    sURL = "http://" & sURL
    End if

    Response.Write "<tr><td>"
    If .fields("Source") = "Ranked" Then
    Response.Write .Fields("Rank") & "</td>"
    Else
    Response.Write "&nbsp;</td>"
    End If
    %>
    <td><%=.Fields("HotelName")%>&nbsp;</td>
    <td><%=.Fields("Location")%>&nbsp;</td>
    <td><%=.Fields("Telno")%>&nbsp;</td>
    <%
    If sURL <>"" Then
    Response.Write "<td><a href=" & sURL & "
    target='_blank'>Website</a></td>"
    Else
    Response.Write "<td>&nbsp;</td>"
    End If
    %>
    <td><a
    href="hotels.asp?id=<%=.Fields("HotelID")%>">Detai ls</a>&nbsp;</td>
    </tr>
    <%
    .movenext
    Loop
    %>

    etc....
    -------------------------------------------------------

    There doesnt seem to be anything to contentious in it.. but clearly there
    must be something...

    Chris

    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:Ov$0YU6%23DHA.1452@TK2MSFTNGP09.phx.gbl...
    > Could you show us what you get with
    >
    > response.write rs.GetString(2,," | ", "<BR>")
    >
    > Bob Barrows

    CJM Guest

  8. #7

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    Sorry... I'm being a numpty again... I was still using the SQL Server DB!

    Bob, your code tallies with my previous output:

    Unranked | Hotelname | TelNo | | Location | 6 | <= 'Unranked'
    plus no Rank value
    etc...



    CJM Guest

  9. #8

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    Ray,

    I tried the example you gave... no - it didnt work either.

    Chris

    "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    message news:%23IHdFe6%23DHA.552@TK2MSFTNGP11.phx.gbl...
    > If you rearrange the order in which you select the columns, does it
    display
    > differently? Eg.
    >
    [snip]


    CJM Guest

  10. #9

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    CJM wrote:
    > Sorry... I'm being a numpty again... I was still using the SQL Server
    > DB!
    >
    > Bob, your code tallies with my previous output:
    >
    > Unranked | Hotelname | TelNo | | Location | 6 | <=
    > 'Unranked' plus no Rank value
    > etc...
    Are you getting any Ranked records?

    You are using the same query in both databases?

    So I don't have to recreate your database to test your code, do this:

    rsInfo.Save <filename>, 1

    and send me the file at [email]reb01501@yahoo.com[/email]

    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  11. #10

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    And you're sure it's not an HTML issue, in that there's an unclosed tag
    somewhere or something? Like, do you values show up in a view source? What
    happens if you just select the rank from a table? Do you have the latest
    version of MDAC? I remember reading things before about column values not
    showing up or generating errors, but this is when the columns are "memo"
    type in Access, and perhaps some large text types in SQL, but never with a
    numeric column.

    Ray at work

    "CJM" <cjmwork@yahoo.co.uk> wrote in message
    news:euPk5m6%23DHA.3220@TK2MSFTNGP10.phx.gbl...
    > Ray,
    >
    > I tried the example you gave... no - it didnt work either.
    >
    > Chris
    >
    > "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    > message news:%23IHdFe6%23DHA.552@TK2MSFTNGP11.phx.gbl...
    > > If you rearrange the order in which you select the columns, does it
    > display
    > > differently? Eg.
    > >
    > [snip]
    >
    >

    Ray at Guest

  12. #11

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)


    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:Offf9q6%23DHA.2520@TK2MSFTNGP11.phx.gbl...
    > Are you getting any Ranked records?
    >
    No.
    > You are using the same query in both databases?
    >
    Exactly the same.
    > So I don't have to recreate your database to test your code, do this:
    >
    > rsInfo.Save <filename>, 1
    >
    > and send me the file at [email]reb01501@yahoo.com[/email]
    >
    Done.


    Just out of interest, here are my two connection strings:
    'Application("Connection") = "Provider=Microsoft.Jet.OLEDB.4.0; Data
    Source=travel.mdb"
    'Application("Connection") = "PROVIDER=SQLOLEDB;DATA
    SOURCE=(local);UID=Username;PWD=password;DATABASE= Travel"

    Cheers

    Chris


    CJM Guest

  13. #12

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    Ray,

    I'm reluctant to say anything is for certain(!), but I would say that it
    isnt an ASP/HTML issue, since the SQL Server version works. [I'm assuming
    you are also following Bob's line of enquiry as well]. The data is coming
    out wrong... I think.

    I'm on MDAC 2.8.

    Chris

    "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    message news:u1RLzw6%23DHA.2592@TK2MSFTNGP10.phx.gbl...
    > And you're sure it's not an HTML issue, in that there's an unclosed tag
    > somewhere or something? Like, do you values show up in a view source?
    What
    > happens if you just select the rank from a table? Do you have the latest
    > version of MDAC? I remember reading things before about column values not
    > showing up or generating errors, but this is when the columns are "memo"
    > type in Access, and perhaps some large text types in SQL, but never with a
    > numeric column.
    >
    > Ray at work
    >

    CJM Guest

  14. #13

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    CJM wrote:
    > "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    > news:Offf9q6%23DHA.2520@TK2MSFTNGP11.phx.gbl...
    >> Are you getting any Ranked records?
    >>
    > No.
    >
    >> You are using the same query in both databases?
    >>
    >
    > Exactly the same.
    >
    >> So I don't have to recreate your database to test your code, do this:
    >>
    >> rsInfo.Save <filename>, 1
    >>
    >> and send me the file at [email]reb01501@yahoo.com[/email]
    >>
    >
    > Done.
    >
    >
    > Just out of interest, here are my two connection strings:
    > 'Application("Connection") = "Provider=Microsoft.Jet.OLEDB.4.0; Data
    > Source=travel.mdb"
    > 'Application("Connection") = "PROVIDER=SQLOLEDB;DATA
    > SOURCE=(local);UID=Username;PWD=password;DATABASE= Travel"
    >
    > Cheers
    >
    > Chris
    This is strange. I see zeroes in the unranked records. You've put zeroes in
    some of them?
    Looking at your query, I think I see a problem:

    where Rank is not null and Rank > 0 and L.LocID=2

    This should be

    where Rank > 0 and L.LocID=2

    If Rank is greater than 0, it is by definition, not null. I'm not sure this
    is causing your problem but... It looks like the ranked records are
    returning Nulls in the Rank column ... I'm not sure why - if the column
    contains Null in those records, it should not return those records at all.
    Try my suggested change and if it makes no difference, I guess I need to see
    the data in your database. Can you zip it up and send it to me? If possible,
    if you could send me a copy containing only the relevant tables and data,
    that would be great.

    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  15. #14

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    > This is strange. I see zeroes in the unranked records. You've put
    > zeroes in some of them?
    > Looking at your query, I think I see a problem:
    >
    > where Rank is not null and Rank > 0 and L.LocID=2
    >
    > This should be
    >
    > where Rank > 0 and L.LocID=2
    >
    > If Rank is greater than 0, it is by definition, not null. I'm not
    > sure this is causing your problem but... It looks like the ranked
    > records are returning Nulls in the Rank column ... I'm not sure why -
    > if the column contains Null in those records, it should not return
    > those records at all. Try my suggested change and if it makes no
    > difference, I guess I need to see the data in your database. Can you
    > zip it up and send it to me? If possible, if you could send me a copy
    > containing only the relevant tables and data, that would be great.
    >
    Sorry, but I cannot reproduce your problem. This code produces the correct
    results as far as I can see:

    cn.open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & server.mappath("travel.mdb")
    ' cn.open "Provider=sqloledb;" & _
    ' "Data Source=xxxxxxx;" & _
    ' "Initial Catalog=test;" & _
    ' "User ID = xxxxx;" & _
    ' "Password = xxxxxx"
    ' set rs=server.createobject("adodb.recordset")
    ' cn.qryHotels rs
    sSQL="Select 'Ranked' as Source, H.HotelName, H.TelNo, " & _
    "H.URL,H.Location,H.HotelID, Rank from (Hotels H " & _
    "Inner Join PrefHotels P on H.HotelID = P.HotelID) " & _
    "Inner Join Locations L on P.LocID = L.LocID" & _
    " where Rank > 0 and L.LocID=2 " & _
    " UNION ALL Select 'Unranked' as Source, H.HotelName, " & _
    "H.TelNo,H.URL, H.Location, H.HotelID, Rank from (Hotels H " & _
    "Inner Join PrefHotels P on H.HotelID = P.HotelID) " & _
    "Inner Join Locations L on P.LocID = L.LocID " & _
    "where (Rank is Null or Rank = 0) and L.LocID=2 " & _
    "ORDER BY Source, Rank;"
    set rs=cn.Execute(sSQL,,1)
    if rs.eof then
    response.write "No records were returned"
    else
    Response.Write "<table border=1><tr><td>"
    sHTML=rs.GetString(2,,"</td><td>", _
    "</td></tr><tr><td>","NA")
    sHTML = Left(sHTML, len(sHTML) - 8)
    response.Write sHTML
    response.write "</table>"
    end if
    rs.close: set rs=nothing
    cn.close: set cn=nothing

    I even imported the tables into my own sql server and verified that I got
    the same results from both sources. I tried it both with the dynamic SQL
    and using the corrected qryHotels saved query (creating a stored procedure
    in SQL Server so I could test from both sources). I'm not sure why you want
    to use dynamic SQL, but ...

    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  16. #15

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    Hello Chris,

    I agree with Bob here. This problem seems strange. I am glad to test for
    you too. If it is convenient for you, please feel free to send me your mdb
    file and asp file. I will test it on my side. :) You can reach me by
    removing online from my email address here.

    Thanks very much.

    Best regards,
    Yanhong Huang
    Microsoft Community Support

    Get Secure! ¨C [url]www.microsoft.com/security[/url]
    This posting is provided "AS IS" with no warranties, and confers no rights.

    Yan-Hong Huang[MSFT] Guest

  17. #16

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    Thanks to all who chipped in... I now have it running...

    I'm not sure what the problem was nor how I cured it - I've done so much
    since yesterday.

    I've re-installed MDAC, I've created a seperate ASP page & rebuilt the code
    from scratch, and tweaked a few other things. Somewhere along the way was
    the solution...

    Thanks again for all your efforts.

    Chris


    CJM Guest

  18. #17

    Default Re: Select Qry: Differing results via Access & ADO (& SQL Server)

    Hi Chris,

    Glad to hear it. :)

    Have a good day!

    Best regards,
    Yanhong Huang
    Microsoft Community Support

    Get Secure! ¨C [url]www.microsoft.com/security[/url]
    This posting is provided "AS IS" with no warranties, and confers no rights.

    Yan-Hong Huang[MSFT] 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