Need help formatting Data.

R

Roman

I have data that looks like the example below:
fistname, last name, multiple rows, each with different data
RON SMITH A
RON SMITH B
RON SMITH C
RON SMITH D
RON SMITH H


My merge program reads data like the sample below:
First name. last name, one row, but multiple cells, each with different data.

RON SMITH A B C D H

Can someone tell me the best way to convert my existing data into the format
above?

Any help is much appreciated.

Thanks
R
 
K

KARL DEWEY

Try a crosstab query like this --
TRANSFORM First([MI]) AS FirstOfMI
SELECT FirstName, LastName
FROM YourTable
PIVOT MI;
 
D

Dale Fye

If Karl's answer doesn't do what you want, then chances are that what you
are already getting looks like:

RON SMITH A B C D H

And you want it to look like:

If that is the case, then what you need is frequently called a normalizing
query. You do this by creating a union query to that looks like:

SELECT FirstName, LastName, Field1 as [NewFieldName]
FROM yourTable WHERE Field1 IS NOT NULL
UNION ALL
SELECT FirstName, LastName, Field2
FROM yourTable WHERE Field2 IS NOT NULL
UNION ALL
SELECT FirstName, LastName, Field3
FROM yourTable WHERE Field3 IS NOT NULL
UNION ALL
SELECT FirstName, LastName, Field4
FROM yourTable WHERE Field4 IS NOT NULL
UNION ALL
SELECT FirstName, LastName, Field5
FROM yourTable WHERE Field5 IS NOT NULL

You will need to replace Field1-Field5 with the names of the fields where
the data A, B, C, D, H are located.

HTH
Dale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top