have table with two columns with datatypes as number and
varchar and the values in
A column like 1,2,3 AND B column values like a,b,c.
now need to display data in a single column as 1,a,2,b,3,c.

Answer Posted / saravanan

Try this way!

create table stest(num int,name varchar(10),value numeric
(10,2));

insert into stest values(101,'SARAN',1000.58);
insert into stest values(102,'KALA',1200.18);
insert into stest values(103,'AYYA',3000.40);
insert into stest values(104,'RATNA',4000.57);

SELECT * FROM STEST;

declare @str varchar(2000);
set @str = null;
select @str=ISNULL(@str+',','')+ltrim(STR(num))+','+name
from stest
select @str;

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the most common sql injection tool?

545


What is linq to sql?

552


When are we going to use truncate and delete?

553


What are the advantages of stored procedure?

544


What is sql basics?

583






Why do we use procedures in pl sql?

518


What language is oracle sql developer?

510


Does sql*plus also have a pl/sql engine?

563


What is sql*loader and what is it used for? : aql loader

623


Describe sql comments?

562


What is on delete set null?

570


Is merge a dml statement?

524


What is the difference between the conventional and direct path loads? : aql loader

695


What port does sql server use?

510


What are the different tcl commands in sql?

620