Sorting Help...

Results 1 to 6 of 6

Thread: Sorting Help...

  1. #1
    pnub Guest

    Default Sorting Help...

    Ok, I am having trouble opening a database and sorting it by a particular (known) column before outputting the data...here is what I have which opens the database (Access &#039 97):<BR><BR>&#060;%<BR>Dim DB_CONNECTSTRING<BR>DB_CONNECTIONSTRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath(strDataBase) & ";"<BR>Set objRecordset = Server.CreateObject("ADODB.Recordset")<BR>objRecor dset.Open strBook, DB_CONNECTIONSTRING, adOpenStatic, adLockPessimistic, adCmdTable<BR>%&#062;<BR><BR>What do I need to change/modify or add to have the database sorted by the column named "font_name" (w/out quotes) and in descending alphabetical order (A at the top, Z at the bottom)?

  2. #2
    Richard L. Guest

    Default RE: Sorting Help...

    You need to change the string in strBook (that you didn&#039t show).<BR><BR>I assume it&#039s something like:<BR><BR>"SELECT * " & _<BR>"FROM myTableName " & _<BR>"WHERE this = that " &<BR><BR>Add:<BR><BR>"ORDER BY font_name"<BR><BR>Going A-Z is, in SQL terms, called Ascending order (low to high value). To sort in Descending order:<BR><BR>"ORDER BY font_name DESC"<BR><BR>Richard

  3. #3
    Join Date
    Dec 1969
    Posts
    463

    Default RE: Sorting Help...

    If you are trying to display the contents of the database you need to use some sort of SQL string. Such as <BR><BR> strSQL = "SELECT * FROM myTable WHERE Font_Name like &#039" & _<BR>strName & "&#039 ORDER BY Font_Name"<BR><BR>Where the ORDER by statement is the sorting command.<BR>You also need to execute the SQL command and write a loop to display the results, but that is another topic in itself.

  4. #4
    pnub Guest

    Default RE: Sorting Help...

    Ok, so I have changed the following the line containing strBook to the following:<BR><BR>objRecordset.Open "SELECT * FROM " & strBook & " ORDER BY font_name DESC", DB_CONNECTIONSTRING, adOpenStatic, adLockPessimistic, adCmdTable<BR><BR>But I took out the "WHERE this = that" portion...I don&#039t know what that part does...how do I use it and it is required because what I have doesn&#039t work?<BR><BR>PS<BR>strBook is the name of the table in the database which is openeded.


  5. #5
    Join Date
    Dec 1969
    Posts
    463

    Default RE: Sorting Help...

    The WHERE statement is used to match records. It will match the records that corespond to the criteria you set for a given field. For instance if you have a field in your Database called First_Name and you want to only return the records which match a given first name such as Rick. You could write your Query like the following.<BR>strName="Rick"<BR> strSQL = "SELECT * FROM tblWebDealerList _<BR>WHERE First_Name = &#039" & strName & "&#039 ORDER BY First_Name"<BR><BR>This will return only the records which have Rick in the First_Name field.<BR>May I also suggest just using the name of the Table you wish to select from instead of a variable. It may make things a little easier for you in the beginning. <BR>

  6. #6
    pnub Guest

    Default RE: Sorting Help...

    IS the WHERE portion of the SQL statement required? I really don&#039t have any stipulations on the data...just to output everything

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •