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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ascending by last name in an expression on a report

Status
Not open for further replies.

CoolFactor

Technical User
Dec 14, 2006
110
US
Hello,
I'm using the following query to produce a report. I want to sort this expression [FirstName] & " " & [LastName] AS Candidate by last name. The result I want to see is for example: If I have these two names Melissa Rean and Alex South, I want my query to show me those names in ascending order by last name like so:
Melissa Rean
Alex South

instead of:

Rean Melissa
South Alex

SELECT [FirstName] & " " & [LastName] AS Candidate, [Party] & "s" AS [Political Party], tbl_Candidates.State, tbl_Candidates.District, tbl_Candidates.Office, [FundType] & "s" AS [Fund Class], [tbl_Candidates Committees].Committee, [tbl_Candidates Funds].Year, Sum(tbl_Ledger.[Contributions/Disbursements]) AS [SumOfContributions/Disbursements]
FROM (tbl_Candidates INNER JOIN [tbl_Candidates Committees] ON tbl_Candidates.CandidateID=[tbl_Candidates Committees].CandidateID) INNER JOIN ([tbl_Candidates Funds] INNER JOIN tbl_Ledger ON [tbl_Candidates Funds].FundID=tbl_Ledger.CandidateFund) ON tbl_Candidates.CandidateID=[tbl_Candidates Funds].CandidateID
GROUP BY [FirstName] & " " & [LastName], [Party] & "s", tbl_Candidates.State, tbl_Candidates.District, tbl_Candidates.Office, [FundType] & "s", [tbl_Candidates Committees].Committee, [tbl_Candidates Funds].Year
ORDER BY [tbl_Candidates Funds].Year;
 
How about:

[tt]SELECT [FirstName] & " " & [LastName] AS Candidate, Party & "s" AS [Political Party], tbl_Candidates.State, tbl_Candidates.District, tbl_Candidates.Office, [FundType] & "s" AS [Fund Class], [tbl_Candidates Committees].Committee, [tbl_Candidates Funds].Year, Sum(tbl_Ledger.[Contributions/Disbursements]) AS [SumOfContributions/Disbursements]
FROM (tbl_Candidates INNER JOIN [tbl_Candidates Committees] ON tbl_Candidates.CandidateID=[tbl_Candidates Committees].CandidateID) INNER JOIN ([tbl_Candidates Funds] INNER JOIN tbl_Ledger ON [tbl_Candidates Funds].FundID=tbl_Ledger.CandidateFund) ON tbl_Candidates.CandidateID=[tbl_Candidates Funds].CandidateID
GROUP BY [LastName] & " " & [FirstName], [FirstName] & " " & [LastName], Party & "s", tbl_Candidates.State, tbl_Candidates.District, tbl_Candidates.Office, [FundType] & "s", [tbl_Candidates Committees].Committee, [tbl_Candidates Funds].Year
ORDER BY [tbl_Candidates Funds].Year;[/tt]
 
Try something like:
SELECT [FirstName] & " " & [LastName] AS Candidate
FROM Employee
GROUP BY [FirstName] & " " & [LastName], Employee.LastName, Employee.FirstName
ORDER BY Employee.LastName, Employee.FirstName;


Learn from the mistakes of others. You won't live long enough to make all of them yourself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top