Convert rows into columns

Hi,

I have a requirement to view rows into columns. I tried with Pivot query but not possible.

Following is the scenario. Please help with query:

CREATE TABLE dbo.test (
action_id numeric,
action VARCHAR(20) NOT NULL,
action_by VARCHAR(20) NOT NULL,
action_date VARCHAR(20) NOT NULL
);

INSERT INTO dbo.test (action_id,action, action_by,action_date)
VALUES (1,'Action1', 'xxxx','12/31/2015'),
(1,'Action2', 'xxxx','12/28/2015'),
(1,'Action3', 'yyyy','12/29/2015')

Output required as follows:

action1
xxxx
12/31/2015

action2
xxxxx
12/28/2015

action3
yyyy
12/29/2015
Thanks
RAO

select val
from dbo.test t
cross apply
(
    values (action), (action_by), (action_date)
)c(val)
1 Like

Thanks gbritton.