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


Please Help Members By Posting Answers For Below Questions

Do you know what is normalization of database? What are its benefits?

730


How do I uninstall sql server 2014?

676


What is the dbcc command and why is it used?

758


Can we add our custom code in ssis?

716


What is the command used to recompile the stored procedure at run time?

775






What are triggers in ms sql server?

795


What is raid and what are different types of raid levels?

775


Does any body please help me what question's have asked for SSRS in the interview?

1871


What are database states in ms sql server?

828


How to configure odbc dsn with different port numbers?

754


Why functions are used in sql server?

667


How to attach adventureworkslt physical files to the server?

816


How do I find the port number for sql server?

687


How to create a view using data from another view?

725


How can you set the threshold at which sql server will generate keysets asynchronously?

732