Query to Output SQL table to Excel or CSV
Query to Output SQL table to Excel or CSV I have been trying to export my table to a csv through a SQL query and no luck. The attempt was using the OUTPUT function but I got an error. Below is the query: SELECT * FROM [table]; OUTPUT TO 'C:foldernew_data.csv' FORMAT TEXT QUOTE '"' WITH COLUMN NAMES; This was the error: Msg 102, Level 15, State 1, Line 81 Incorrect syntax near 'OUTPUT'. Msg 319, Level 15, State 1, Line 84 Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon. Am I not using the OUTPUT function correctly and is there an alternative query in SQL? the ";" after the SELECT terminates the statement. So you have two statements here: SELECT ...; and OUTPUT TO ...; Remove the semicolon after the select and see if that works. docs.microsoft...
