Home > Mobile >  Add table data from sql server to text file with select query
Add table data from sql server to text file with select query

Time:05-27

I am trying to export a table present in ms sql server 2017 to a text file on my system. I am writing the following command in sql server query window

SELECT *
FROM Input
INTO OUTFILE 'C\filename.txt'

Now I write this command the sql help gives me error that

incorrect syntax near 'INTO'

Then I tried to new query

SELECT *
INTO OUTFILE 'C:\filename.txt'
FROM Input

Now it gives me error that

incorrect syntax near 'C:/filename.csv'

Please help me regarding this. I am not able to remove these error and get a working sql

CodePudding user response:

You should be able to retrieve the data from the db and insert it into the .txt file using the php fopen() function to append/write to the file.

CodePudding user response:

This seems to be what you need: https://www.mssqltips.com/sqlservertip/1633/simple-way-to-export-sql-server-data-to-text-files/

Also CLR may be a solution (not high recommended thought), because you will write code in vb or C# and it will be converted to SQL Stored procedure/Function.

  • Related