question

tushar.ghodake avatar image
tushar.ghodake asked

how to import query execution message in a text file

Hi, I want to store my query execution message on somewhere on my drive. let say I execute a query select * from table_name; then it gives a msg '(30556 row(s) affected)' and I want to store this message in a text file. Is there any query or setting so I can do it along with my script?
sql-server-2008scriptquery-resultsquery-out
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
If you run the T-SQL command from sqlcmd.exe or PowerShell, then you get the entire output that can be saved as a file. You can do the same thing if you're building your own commands using a programming language. If you're running the commands through Management Studio, you can have the output go to text instead of to grid. That will include messages with the results so that everything can be saved to a single file. In a query window you can right click on the query and select "Results to" from the context menu and then "Results to Text" or hit CTL-T in the query window. There's also a button on the toolbar.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.