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
Answer Posted / 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 |
Post New Answer View All Answers
What is bit data type?
What is temporal data type?
What is a result set object returned by mssql_query()?
Explain filestream storage of sql server 2008?
Are null values the same as that of zero or a blank space?
Why we use functions in sql server?
What is sql server profiler?
What is the new security features added in sql server 2014? : sql server security
What is multilevel indexing?
What is database replication?
How to create a simple stored procedure in ms sql server?
How to retrieve error messages using odbc_errormsg()?
What is the parse query button used for?
Explain the ways to controlling cursor behavior?
What are the database objects? : SQL Server Architecture