I’m writing a small SQL query for work to automate some jobs that we regularly do. I have managed to figure out most of it but one thing is bugging me.
I have to generate a CSV file that contains a the output from our ERP system and at the beginning and end of the query I have to have a start text and an EOF. I have somewhat solved this by making the query and then using Union all
to insert the start and EOF in the file. The problem is however that the start and EOF line has the wrong format.
But let me start by attaching a sample that show the principle of the query
Select
'Meta Data:12 seperator:; Endtag EOF' as 'USER'
,'' as 'ID'
,'' as 'Date'
union all
Select top 3
bruger as 'USER'
,id as 'ID'
,dato as 'DATE'
from dbo.TableName
union all
Select
'EOF' as 'USER'
,'' as 'ID'
,'' as 'Date'
The Results from this looks like this when I save it as a CSV
”Meta Data:12 seperator:; Endtag EOF”;;2024-05-01
User1;123;2024-05-01
User2;456;2024-05-01
User3;789;2024-05-01
EOF;;2024-05-01
However I want the result to be like this
Meta Data:12 seperator:; Endtag EOF
User1;123;2024-05-01
User2;456;2024-05-01
User3;789;2024-05-01
EOF
I hope you have some good suggestions for me.
Tom eriksen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.