In this article I am trying to demonstrate, how to generate comma separated value (CSV) from a particular table objects fields.
So I am going to demonstrate it as step by step that we can understand it properly.
Step-1 [ The base Table Objects ]
CREATE TABLE #tbl_Student
(Roll INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
Sname VARCHAR(50) NOT NULL)
Step-2 [ Inserting Records ]
INSERT INTO #tbl_Student
SELECT * FROM #tbl_Student
Step-3 [ Creating CSV format ]
SELECT SUBSTRING((SELECT ',''' + a.Sname+''''
FROM #tbl_Student a
ORDER BY a.Sname
FOR XML PATH('')),2,200000) As RESULT;
It is easy but very useful.
Hope you like it.
Posted by: MR. JOYDEEP DAS