hi,
i have a table called names and field name
select * from names
name
a
b
c
d
i want to display like this
name
a,b,c,d
how it is possible
Regards
Baiju
Answers were Sorted based on User's Feedback
Answer / soorai ganesh
Hi Friend,
If u use SQLSERVER 2005 u can try like this............
CREATE TABLE EMP ( ENAME VARCHAR(25))
INSERT INTO EMP VALUES('Ganesh')
INSERT INTO EMP VALUES('Narendra')
INSERT INTO EMP VALUES('Rinku')
INSERT INTO EMP VALUES('Selvam')
INSERT INTO EMP VALUES('Kirti')
SELECT REPLACE(REPLACE(
( SELECT ENAME AS EmpName FROM EMP FOR XML PATH ('') ) ,'<EmpName>',''),'</EmpName>',',')
| Is This Answer Correct ? | 6 Yes | 0 No |
Answer / prasanna
create procedure loopcure
as
BEGIN
declare @a int, @b varchar(020), @l int, @c varchar(020),
@D varchar(020)
SET @D = ''
declare loopcur cursor for select id from names
open loopcur
fetch next from loopcur into @b
while @@fetch_status = 0
begin
select @C = LTRIM(RTRIM(@B)) + ','
select @D = LTRIM(RTRIM(@D)) + LTRIM(RTRIM(@C))
fetch next from loopcur into @b
end
close loopcur
deallocate loopcur
select @d = left(@d, len(@d)-1 )
select @d as final
END
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / gopi muluka
CREATE TABLE Names (Name VARCHAR(50))
GO
INSERT Names
SELECT 'A'
UNION
SELECT 'B'
UNION
SELECT 'C'
UNION
SELECT 'D'
GO
-- FIRST METHOD
DECLARE @Name VARCHAR(50)
SELECT @Name=ISNULL(@Name,'')+ COALESCE(Name,',')+',' FROM
Names
SELECT LEFT(@Name,LEN(@Name)-1)
GO
--SECOND METHOD
DECLARE @chrString as varchar(200)
SET @chrString=''
SELECT @chrString=@chrString + ',' + Name FROM Names
SELECT SUBSTRING(@chrString,2, LEN(@chrString))
GO
DROP TABLE Names
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / kulwinder
DECLARE @chrString as varchar(200)
select @chrString=@chrString + ',' + Name from Names
? @chrString
| Is This Answer Correct ? | 1 Yes | 1 No |
Differences between functions and stored procedures?
8 Answers 247Customer, Accenture,
What is the full form of ddl?
How do I schedule a sql server profiler trace?
Are there any preferred steps that need to be taken care of before starting the installation of sql server 2000?
what is the Enterprise manager(2000) and management studio (2005)?
One table how may column and Primary key
Explain Capacity planning to create a database? and how to monitor it?
What is the difference between SQL notification and SQL invalidation?
What are constraints? Explain different types of constraints?
26 Answers Emsang, Kendriya Vidyalaya(Kvs), Polaris, Wipro,
What is the difference between a local and a global variable?
How to replace null values in expressions using isnull()?
Explain the difference between clustered and non-clustered index?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)