0

I am developing in ASP VBScript at work and need to run a SELECT DISTINCT query but I am having some troubles.

I have other queries in my code that work perfectly fine, that do not use SELECT DISTINCT.

Here is what I am using:

            Dim sections()
            c = 1
            set conn=Server.CreateObject("ADODB.Connection")
            set rs=Server.CreateObject("ADODB.Recordset")
            conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=******;User ID=Admin;" & _
                    "DATA SOURCE=" & Server.MapPath("modules.mdb")
            rs.open "SELECT DISTINCT section FROM modules WHERE area='First' ORDER BY lvl ASC",conn
            ReDim sections(10)
            do while not rs.EOF
              sections(c) = rs("section")
              c = c + 1
              rs.MoveNext
            loop
            rs.Close
            conn.Close
            set rs = nothing
            set conn = nothing

Which gives me this error:

error '80004005' 

on the line of the SQL query

beyondit01
  • 37
  • 7

1 Answers1

1

The only way to fix this is to use "GROUP BY" instead of "DISTINCT"

SELECT DISTINCT section FROM modules WHERE area='First' ORDER BY lvl ASC
SELECT section FROM modules WHERE area='First' GROUP BY section ORDER BY lvl ASC
Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45
Frank
  • 11
  • 1