Reputation: 14731
Below is my table script and records.
create table prods
(prod_no varchar2(12));
insert into prods
values('MOBILE');
insert into prods
values('LAPTOP');
select prod_no from prods;
gives me
MOBILE
LAPTOP.
How can I get the results like the following?
MOBILE LAPTOP
. I would like the two records in one single row.
Upvotes: 0
Views: 204
Reputation: 1588
Try this:
--Transact-SQL
--In this case, store in the variable varchar values
declare @result varchar(max) = '';
select @result = @result + prod_no + ' ' from prods;
select @result;
Upvotes: 0
Reputation: 6336
create table prods
(prod_no varchar2(12));
insert into prods
values('MOBILE');
insert into prods
values('LAPTOP');
select
rtrim (xmlagg (xmlelement (e, prod_no || ' ')).extract ('//text()'), ' ') list
from
prods;
LIST
---------------------------------------------------------
MOBILE LAPTOP
1 row selected.
SQLFIDDLE:link
Upvotes: 2
Reputation: 14292
I think you need to pivot the table. Go through the below URL
Visit: http://blogs.msdn.com/b/spike/archive/2009/03/03/pivot-tables-in-sql-server-a-simple-sample.aspx
Upvotes: 0