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
Do you know what is normalization of database? What are its benefits?
How do I uninstall sql server 2014?
What is the dbcc command and why is it used?
Can we add our custom code in ssis?
What is the command used to recompile the stored procedure at run time?
What are triggers in ms sql server?
What is raid and what are different types of raid levels?
Does any body please help me what question's have asked for SSRS in the interview?
What are database states in ms sql server?
How to configure odbc dsn with different port numbers?
Why functions are used in sql server?
How to attach adventureworkslt physical files to the server?
How do I find the port number for sql server?
How to create a view using data from another view?
How can you set the threshold at which sql server will generate keysets asynchronously?