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 a data source file?
What is openxml in sql server?
What is difference between order by and group by?
What is correlated subquery in sql server?
How can you find out how many rows returned in a cursor?
How does recursive cte works in sql server?
Name few endpoints exposed by ssrs 2012?
Explain different types of lock modes in sql server 2000?
can a database be shrunk to 0 bytes, if not, why? : Sql server administration
What is PROJECTION Operation?
What do you mean by sql server 2005 express management tools?
Describe how to use the linked server?
What is plan freezing?
Explain about system database?
what is the Ticketing tool used in Wipro technologies at Bangalore...???