Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

What is bit data type?

978


What is temporal data type?

869


What is a result set object returned by mssql_query()?

1070


Explain filestream storage of sql server 2008?

950


Are null values the same as that of zero or a blank space?

985


Why we use functions in sql server?

1011


What is sql server profiler?

954


What is the new security features added in sql server 2014? : sql server security

943


What is multilevel indexing?

878


What is database replication?

1077


How to create a simple stored procedure in ms sql server?

974


How to retrieve error messages using odbc_errormsg()?

990


What is the parse query button used for?

981


Explain the ways to controlling cursor behavior?

871


What are the database objects? : SQL Server Architecture

984