Thursday, September 23, 2010

Comma Seperated Values from Tables in SQL

Hi Everyone,
This blog helps you to display the table column value to comma seperated values.
First we have to select the table and before the column name, kindly add a ','.
Then keep the select as inner query and use substring in the select query.
This substring will need 3 parameters - Expression,Start-Position,Length.
Give this as it is! the value 2 has given as start position to remove the first comma present in the final list.
 
 
SELECT SUBSTRING(
(
SELECT ',' +
s.Name
FROM
HumanResources.Shift s
ORDER BY
s.Name
FOR XML PATH('')),2,200000) AS
CSV
GO


By this way, We can make the table to csv..
 
Regards 
M.K.Kannan..

No comments:

Post a Comment

HTML/JAVASCRIPT BLOG

You can find the help for html and javascript codes

Any Doubts Contact my Mail-ID:
kannan.mkv@gmail.com