Greetings,
Example data in desired sort order from query:
This is pretty hard to explain and probably even more difficult to accomplish. This query is really about "Joe Smith". The basic SQL is as such:
I need the first "group" of records to be when Joe Smith is PDC_Rep, and within that group, I want the PDC to be sorted alphabetically; Now when Joe Smith is NDC_Rep, I'd like to sort those NDC's alphabetically as well.
I have tried playing around with IIF statements to give me something numeric to sort by, such as:
xSort: IIF([PDC] = "Joe Smith", 0, 100)
ySort: IIF([NDC] = "Joe Smith", 1, 100)
That works great in grouping the PDC_Rep and NDC_Rep sections together, but not sure how to get the PDC and NDC fields sorted alphabetically WITHIN those groupings.
I'm not too great with UNION queries yet, but I'm thinking that is the direction I need to look at. Additionally, this data will eventually appear in a report, which is where the sort-order is required. If there are any other sorting options that are available within the report, that would obviously be a good option as well.
Any ideas, suggestions? Thanks in advance, as always.
~Melagan
______
"It's never too late to become what you might have been.
Example data in desired sort order from query:
Code:
OrderID PDC_Rep PDC NDC_Rep NDC
1234 Joe Smith Al Johnson Shane Doe Ron Whit
1237 Joe Smith Bob Thorn Joe Smith Bob Thorn
1233 Joe Smith Carl Smith Phil Jones Zed Xy
1238 Phil Jones Zed Xy Joe Smith Al Johnson
1239 Shane Doe Ron Whit Joe Smith Al Johnson
1230 Phil Jones Jeff Wright Joe Smith Anton Notan
1240 John Doe Jim East Joe Smith Bob Thorn
1241 Shane Doe Bill Smith Joe Smith Carl Smith
1242 Phil Jones Anton Notan Joe Smith Don Hersch
This is pretty hard to explain and probably even more difficult to accomplish. This query is really about "Joe Smith". The basic SQL is as such:
Code:
SELECT t.OrderID, t.PDC_Rep, t.PDC, t.NDC_Rep, t.NDC
FROM tblMyTable as t
WHERE t.PDC_Rep = "Joe Smith" OR t.NDC_Rep = "Joe Smith"
ORDER BY _____help_____
I need the first "group" of records to be when Joe Smith is PDC_Rep, and within that group, I want the PDC to be sorted alphabetically; Now when Joe Smith is NDC_Rep, I'd like to sort those NDC's alphabetically as well.
I have tried playing around with IIF statements to give me something numeric to sort by, such as:
xSort: IIF([PDC] = "Joe Smith", 0, 100)
ySort: IIF([NDC] = "Joe Smith", 1, 100)
That works great in grouping the PDC_Rep and NDC_Rep sections together, but not sure how to get the PDC and NDC fields sorted alphabetically WITHIN those groupings.
I'm not too great with UNION queries yet, but I'm thinking that is the direction I need to look at. Additionally, this data will eventually appear in a report, which is where the sort-order is required. If there are any other sorting options that are available within the report, that would obviously be a good option as well.
Any ideas, suggestions? Thanks in advance, as always.
~Melagan
______
"It's never too late to become what you might have been.