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 document index?
Do you know clustered and non-clustered index?
What is the purpose of self join?
Explain differences between web edition and business edition?
What are temporal tables in sql server 2016?
How can we solve concurrency problems?
Explain the categories of stored procedure?
What is the difference between ddl,dml and dcl commands?
What are a scheduled jobs?
What is the filtered index?
Do you know what are the properties of the relational tables?
What is factless fact table? : sql server analysis services, ssas
How do I find sql server instance name?
What is ms sql server service broker?
what is a live lock? : Sql server database administration