Turning Access columns into rows

It has been a couple of years since I have done this, so I need to brush up.

I have a query (QRYSOMETHING) that has 3 columns and 1 record.

length | width| height

   20in |   2ft  |  10ft

I need to rotate that to say

length | 20ft

width  | 2ft

height | 10ft

I thought it was:

SELECT [qrysomething].length,[qrysomething].width,[qrysomething].height

FROM [qrysomething]

UNION ALL

I remember it being simple.  What is wrong with my syntax?

Thanks in advance!

July 16th, 2015 1:03am

Hi Zayneandaustin,

In SQL Server, the expected output can be achieved with a UNION ALL statement as below. I've no much idea on Access but I believe it would be easier to tweak the below to make it work in Access.

DECLARE @qrysomething TABLE
(
length INT,
width INT,
height INT
);

INSERT INTO @qrysomething VALUES(20,2,10);
 
SELECT 'length' attribute,[qrysomething].length
FROM @qrysomething [qrysomething]
UNION ALL
SELECT 'width' attribute,[qrysomething].width
FROM @qrysomething [qrysomething]
UNION ALL
SELECT 'height' attribute,[qrysomething].height
FROM @qrysomething [qrysomething]

Since this is a forum for Microsoft SQL Server, for questions on Access I would suggest your post them on a dedicated Access forum. You would get more prompt and precise response.

If you have any question, feel free to let me know.
Free Windows Admin Tool Kit Click here and download it now
July 16th, 2015 11:26pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics