SQL Server, How to easily create a text file with the result of your query (another easy tips)
Hello friends,
Its the time for another "useful but fast & easy” tips!
The question of today is:
I have a query, a select on my database the "give me" a resultset which I need to export to a text file. How to produce the text file? maybe this operation must be schedulable.
So, How to do it?
We can take advantage of the SqlCmd command that we have already used here: execute T-SQL commands from the command line
Just prepare your select as in the picture below and save it into a .SQL file.
Then open a command promp and type:
SqlCmd -U xx -P yyyyy -i select.sql -o c:\dati.txt
where
-U username
-P password
-i the location of your script
-P password
-i the location of your script
-o is the file name that will be filled up with your data!
Et voilà!
I wish you a great day!
Luca
This comment has been removed by the author.
ReplyDeleteThank you so much.I guess this code snippet can really be helpful to solve complex operations and problems such as bugs and errors.
ReplyDelete<a href="https://zappysys.com/blog/import-rest-api-json-sql-server/> SQL Server Load Soap API </a>