I am trying to write a query in CSV format, it is below:
SELECT SUBSTRING
(
(
SELECT ',' + [symbol], + ',' + [date] + ',' + [price]
FROM csvFormatTable
FOR XML PATH('')
)
,2,200000
)
AS CSV
and it mostly gives the correct result apart from the ','
at the end of the line but I do want to replace it with a line break. I've seen CHAR(10) and similar stuff like that but it does not give a line break but instead a '#x0D'
. The result of the query above is what I have (without the char(10) stuff) below:
symbol,date,price,mikeCode,2019-04-10,50,mikeCode,2019-04-11,200,mikeCode,2019-04-12,10,
Where as it should be:
symbol,date,price
mikeCode,2019-04-10,50
mikeCode,2019-04-11,200
mikeCode,2019-04-12,10
It needs the line break so it can be readable as a CSV.