Hi,
I have a table with some data in my sql database. I want to print the result of that table in to a file in my system from sql . I found some ways to print text from sql to a text format file. My requirement is to send the sql command output into a text file.Please suggest a way to solve my problem.
Naveen KumarPosted Oct 10, 2023, 11:56 AM
If you are OK to use xp_cmdshell, then try below query.
Ensure your server have configured to run xp_xmdshell, if not run the below query to configure it.
Sachin SinghPosted Oct 4, 2023, 11:04 AM
You can use the command Promt
where c:\sql\myquery.sql is the path of the SQL query file.
AnuPosted Oct 2, 2023, 10:46 AM
Hi,
I tried the way which you suggested, but getting below error
Jithu ThomasPosted Oct 2, 2023, 10:00 AM
In SQL Server the
bcputility for exporting query results to a text file. You can execute it from SQL Server Management Studio or a command prompt. Here's an example:bcp "SELECT column1, column2 FROM your_table" queryout "C:\path\to\your\file.txt" -c -TReplace
column1, column2with the columns you want to export,C:\path\to\your\file.txtwith the path to your output file, andyour_tablewith the name of your table.