// Posted By Suresh
DECLARE C1s CURSOR FOR
SELECT C1 FROM tablename order by C1 desc
DECLARE @C1s VARCHAR(8000)
DECLARE @C1 VARCHAR(10)
OPEN C1s
FETCH NEXT FROM C1s INTO @C1
WHILE @@FETCH_STATUS = 0
BEGIN
SET @C1s = ISNULL(@C1s + ',', '') + @C1
FETCH NEXT FROM C1s INTO @C1
END
CLOSE C1s
DEALLOCATE C1s
SELECT @C1s AS C1s
// ANOTHER Method
SELECT Name
FROM Emp_Master
GO
-- Get CSV values
SELECT SUBSTRING(
(SELECT ',' + s.Name
FROM Emp_Master s
ORDER BY s.Name
FOR XML PATH('')),2,200000) AS CSV
No comments:
Post a Comment