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
I have a table Events Events containing cardno,time,id,name--each id has a cardno my requirement is every day each employee swipe the card several times i want to calculate first and last time of each card the output should be name 1 2 6 7 in out in out holiday holiday xxx 09:30 06:30 09:40 06:45 where 1,2...... are dates for example january 1,2, etc. 6 and 7 are saturday and sunday how it is posssible
Define Unique Key?
hi, how to link a text file and a .rpt file in my tables of sql server and to retrieve those records for further use. reply me as soon as possible.
How to replace given values with null using nullif()?
Which are new data types introduced in sql server 2008?
You are designing a database for your human resources department in the employee table, there is a field for social security number, which cannot contain null values if no value is given, you want a value of unknown to be inserted in this field what is the best approach?
Differentiate between a local and a global temporary table?
What is sql server english query?
What are the disadvantages of using querystrings to send data from one page to another?
How do I run sql server 2014?
What is wrong with sql server client libarary dll, ntwdblib.dll?
What are the instances when triggers are appropriate?
Explain about protocol layer present in SQL server?
What is recompile sql server?
Is a null value equal to anything? Can a space in a column be considered a null value? Why or why not?