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!

Group lables? Not sure how to best describe this question. 2

Status
Not open for further replies.

Melagan

MIS
Nov 24, 2004
443
US
This one should be fun ... say I have a table that looks like this:

First Last County
John Adams Fresno
Bill Will Fresno
Jane Doe Fresno
Alex Jones Los Angeles
Pete Smith Los Angeles
Robert James Ventura
Paul Garcia Ventura


And I want the SQL to present the data like this:
First Last County
Fresno
John Adams Fresno
Bill Will Fresno
Jane Doe Fresno
Los Angeles
Alex Jones Los Angeles
Pete Smith Los Angeles
Ventura
Robert James Ventura
Paul Garcia Ventura

Code:
SELECT t.First, t.Last, t.County
FROM tblLables
ORDER BY t.County

Maybe some kind of IIF statement for t.First ?

~Melagan
______
"It's never too late to become what you might have been.
 
I think it's more a report issue than a query ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Why bother when you can write a report in 45 seconds to do it that way????????????

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Because I export this recordset to an excel spreadsheet. Currently, I filter the data then insert a blank row between every row, then type in the County name above each "group" so that the sheet looks like the data I posted above.

The point is to have a mailing lable print with just the county name before each group of lables for each county.

If there is a way to accomplish all of this within a report and not even bother with Excel, I'm all for that.


~Melagan
______
"It's never too late to become what you might have been.
 
A starting point:
SELECT t.First, t.Last, t.County FROM tblLables AS t
UNION SELECT '', '', County FROM tblLables
ORDER BY 3, 2, 1;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PH that's really close - this is the returned result.

union.jpg


And this is what I'm after:

expected.jpg


I prefer the data to be layed out this way because of the way the mail merge is set up. The county field is aligned to the upper right and very opaque, whereas the First field is aligned center, bigger font, and bold. Example:

lables.jpg


Maybe it would be easiest to leave the SQL as-is and do the special sorting/formatting in Excel VB ?



~Melagan
______
"It's never too late to become what you might have been.
 
and this ?
SELECT t.First, t.Last, t.County FROM tblLables AS t
UNION SELECT County, '', County FROM tblLables
ORDER BY 3, 2, 1;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I am again amazed! I need to look a lot more closely at Union queries.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Nice. I second the kind comments from Traingamer and agree that I need to look into Union queries a bit further. Thanks again PH!

~Melagan
______
"It's never too late to become what you might have been.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top