Welcome to Windows Help!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

SQL - query moving column to a row

 
   Windows Help (Home) -> Microsoft Access RSS
Next:  Jet and Active Directory  
Author Message
Kamil

External


Since: Dec 1, 2008
Posts: 4



(Msg. 1) Posted: Thu Dec 04, 2008 11:43 pm
Post subject: SQL - query moving column to a row
Archived from groups: microsoft>public>access (more info?)

Hi.
I have a table with fields:
KEY;a;b

I would like to create a query which will move the data from field "b"
to next row:
KEY;a
KEY;b.

Example:
ID;phone1;phone2
=>
ID;phone1
ID;phone2

Is it possible?
Best regards,
Kamil

 >> Stay informed about: SQL - query moving column to a row 
Back to top
Login to vote
Allen Browne

External


Since: Dec 2, 2008
Posts: 25



(Msg. 2) Posted: Fri Dec 05, 2008 5:26 pm
Post subject: Re: SQL - query moving column to a row
Archived from groups: per prev. post (more info?)

Use a UNION query, like this:

SELECT Table1.[KEY] AS TheKey,
[A] AS ThePhone
"Phone1" AS TheSource
FROM Table1
WHERE [A] Is Not Null
UNION ALL
SELECT Table1.[KEY] AS TheKey,
[B] AS ThePhone
"Phone2" AS TheSource
FROM Table1
WHERE [B] Is Not Null
ORDER BY TheKey;

Results will be read-only.

TheSource will be meaningful only if you have different types of numbers in
your existing columns.

Use UNION rather than UNION ALL if you want Access to de-duplicate. (Takes
longer to run.)

I aliased your KEY field, as KEY is a reserved word. It's probably not your
real field name, but here's a list of names to avoid when designing tables:
[URL="http://allenbrowne.com/AppIssueBadWord.html"]http://allenbrowne.com/AppIssueBadWord.html[/URL]

Ultimately, you might consider creating a related table to hold the phone
numbers for your KEYs, so they are actually stored in the way you requested
(which is correctly normalized.)

 >> Stay informed about: SQL - query moving column to a row 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Query combobox unbound column - Does anyone know if it is possible to run an append query referencing a column in a combobox. In otherwords, my combobox is bound to column 0 - ID and column 1 is the name. I want to append it to another table as the name, not ID? Thanks in advance...

Can not change data once i bases a query on a query - I have a despatch System that shows a customers orders with the products to be despatched Its on a Contious form based on a query. On the form i also want to show the Quantity that need to be despatched as the order might be despated in parts Th I hav...

Moving data between list box - Hi Guys, I am trying to use 2 list box to move the highlighted data between them, I have a list of data coming from a Table in first list box, and 2 buttons, 1 button to move the data from the list box 1 to the list box 2 and the second to move the...

converting row into column - I have a table with doctors' information Their addresses are linsted in differnt rows i would like to create a row off addresses with one unique record.

How do I add a COLUMN to combo box - I have two combo boxes on a form. The first combo box gets info from tblPOTODO using a select query and the following code. SELECT tblPOTODO.PART_NO, tblPOTODO.NAME, tblPOTODO.MANUF1, tblPOTODO.MANUF1_PN, tblPOTODO.MANUF2, tblPOTODO.MANUF2_PN,..
   Windows Help (Home) -> Microsoft Access All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]