473,473 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

listing data in columns dependent on letter of alphabet

I have a simplelist of names that I got from the database. I have
written all the names from the simple list to the screen.
what I'm looking to do is the following:
A-H I-P Q-Z
anne isabella rachel
beth jen steph
. . .
. . .
. . .
how do I take a simple list of every name and put it under it's
appropriate letter column?

Nov 13 '05 #1
1 1593
<em****@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I have a simplelist of names that I got from the database. I have
written all the names from the simple list to the screen.
what I'm looking to do is the following:
A-H I-P Q-Z
anne isabella rachel
beth jen steph
. . . how do I take a simple list of every name and put it under it's
appropriate letter column?


SQL is not very good at this sort of thing - but you could do it something
like this.

First your names table

create table names(persName varchar(50) not null primary key)
insert into names(persName) values ('anne')
insert into names(persName) values ('beth')
insert into names(persName) values ('isabella')
insert into names(persName) values ('jen')
insert into names(persName) values ('rachel')
insert into names(persName) values ('steph')

then you need a table for the bins:

create table bins(binName char(3) not null, binStart char(1) primary key,
binEnd char(1))
insert into bins(binName,binStart,binEnd) values('A-H','A','H')
insert into bins(binName,binStart,binEnd) values('I-P','I','P')
insert into bins(binName,binStart,binEnd) values('Q-Z','Q','Z')

Now, here is a query that will give you a ranking for each name within it's
own bin:

select A.persName, A.binName, count(*) as rank
from
(
select n.persName, b.binName
from names n inner join bins b on n.persName >= b.binStart
and n.persName <= b.binEnd
) as A
inner join
(
select n.persName, b.binName
from names n inner join bins b on n.persName >= b.binStart
and n.persName <= b.binEnd
) as B
on A.binName = B.binName
and A.persName >= B.persName
group by A.persName, A.binName

You end up with a resultset that looks like this:

anne A-H 1
beth A-H 2
isabella I-P 1
jen I-P 2
rachel Q-Z 1
steph Q-Z 2

(the formatting may get messed up). Finally, you can feed this into a
crosstab query to get the grid you need.


Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: elyob | last post by:
I've got a list of towns in a MySQL database, which I currently pull from the database ... e.g. http://www.local-hotel.com/townsall/AU/ I now want to put a etc menu at the top, which will...
0
by: em_lom | last post by:
I have a simplelist of names that I got from the database. I have written all the names from the simple list to the screen. what I'm looking to do is the following: A-H I-P ...
8
by: Mansi | last post by:
Given the following declaration: String letter = "A"; Is there a way that I can increment letter so that "B" is returned? Is there a way that I can add an offset so that let's say, "G" is...
9
by: booksnore | last post by:
I am writing some code to search for strings that contain every letter of the alphabet. At the moment I am using the method below to check to see if a string contains every letter of the alphabet....
3
by: KK | last post by:
Hello all, I have several classes binded by one common interface - say 'sum' interface which calculates the sum of all the class elements of type 'int'. class Alphabet { int _a; int _b; int...
0
by: pchahar | last post by:
Write a program to process a text file. The program will determine how many unique words there are in the text file that begin with each letter of the alphabet. The text file name will be given as a...
2
by: Protoman | last post by:
How would I write a user defnable letter swapping algorithm? I've written an Enigma encrypting program, and I need to redo the plugboard function. Right now, the letter swapping is fixed. I need to...
6
by: pj | last post by:
Hi, I 'm currently writing a program that performs transliteration (i.e., converts greek text written using the english alphabet to "pure" greek text using the greek alphabet) as part of my...
6
by: =?ISO-8859-2?Q?Boris_Du=B9ek?= | last post by:
Hi, I have trouble defining a macro - see the following code: #define LETTER_STRAIGHT(let) let = L'#let' enum Letter { LETTER_STRAIGHT(A), LETTER_STRAIGHT(B), LETTER_STRAIGHT(C),
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.