Exporting Query Results to CSV Not Receiving What I see

Greetings, I'm using SQL 18.12.1

I run my query that assigns new titles to the fields for readability.
I also have a result that is from a CASE WHEN THEN END.
I have a result that collates two fields (first/last name)

I receive my results, which shows the information as I want.

I then 'Save Results As...', choose my file name and location for the CSV.

I open the CSV and see

  • Fields that are not in my SQL Results display at all
  • Fields that should be as one result but show in separate columns, like 'FirstName' and 'LastName'
  • Fields that show appear in my CSV, as they do in me SQL Results, but don't.

I just want WYSIWYG.

Your advice is most appreciated.

	General.ErrorLog.ErrorLogID AS 'ID', 
	General.ErrorLog.WhenOccurred AS 'When', 
	General.ErrorLog.ErrorMessage AS 'Error Message', 
	General.ErrorLog.Source, 
	General.ErrorLog.ApplicationProcedure AS 'Application Procedure', 
	General.ErrorLog.LastSQL AS 'Last SQL', 
	CASE
	WHEN General.ErrorLog.Workstation = 'DC05951' THEN 'U1-CLL'
	WHEN General.ErrorLog.Workstation = 'DC07461' THEN 'U1-CLM'
	WHEN General.ErrorLog.Workstation = 'DC07552' THEN 'U1-CLR'
	ELSE '--??--' END AS 'Loc',
	Security.Users.FirstName + ' ' + Security.Users.LastName AS 'Name'
FROM	
	General.ErrorLog INNER JOIN
	Security.Users ON General.ErrorLog.UserID = Security.Users.UserID
WHERE	
	General.ErrorLog.WhenOccurred > '04/06/2023'  AND
	General.ErrorLog.ErrorMessage LIKE '%Timeout%'
ORDER BY
	--Found just after the dbo. listings in Tables
	General.ErrorLog.WhenOccurred

Picture of SQL Headings:

Picture of CSV Headings:

  1. You should change to using square brackets instead of quotes for defining field names.
  2. I think it could be that the CSV format doesn't like having spaces in field names so you should just set your field names to not use spaces and you can deal with that later.

I'm not 100% sure about any of that but just throwing something out there to try. I don't currently have a way to test.