Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting SORT BY

Status
Not open for further replies.

mdsoren

Programmer
Aug 25, 2002
15
US
I have tried to search the forum, but don't see anything like what I am trying to do...

I have my SQL statement built on the fly based on values selected from 5 combo boxes users may choose as many or as few, but at least one. No matter which elements they are searching the database for, the report always returns the same fields in the report, Company Name, Attorney's name and state company is organized in.

My problem is I want to sort the resulting recordset based on a "constructed" field -- I am not sure the technical term, it's NOT an alias, I use a SELECT inside of my main SELECT to return names from an addressbook table.

The tables being searched only have ID#'s referencing the addressbook wherever a name is involved, but I need to retrieve the name.

Here's a sample of the SQL my app generates when a user wants to see all companies in 'Iowa'...
Code:
SELECT DISTINCT 
    tblCorp.ID, tblCorp.ResponsibleAttorney,  tblOrganization.StateOorA,
  (SELECT FullName FROM tblAddressBook
  WHERE tblCorp.ID = tblAddressBook.ID) AS EntityName,
  SELECT FullName FROM tblAddressBook
  WHERE tblCorp.ResponsibleAttorney = tblAddressBook.ID) 
  AS RespAtty
FROM tblCorp, tblOrganization
WHERE tblCorp.ID = tblOrganization.CorpForeignKey AND 
    (tblOrganization.StateOorA = 'Iowa')
ORDER BY tblCorp.ResponsibleAttorney

This sorta works, except that the Responsible Attorney field in tblCorp is just a number. The attorney's companies are at least grouped together, but the report is not in alphabetical attorney order, but instead ordered by their ID number from the addressbook. As attorneys get added and deleted from the addressbook they will no longer be in alphabetical order as they are currently.

How do I get it to sort on the "constructed" field named 'RespAtty' instead of 'ResponsibleAttorney'???
 
BIG THANX SwampBoogie!!! That fixed it. Whoopie!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top