Here is the email received just the other day –
I have been using sqlcmd for a long time and I find it very comfortable. I am going to soon learn Powershell as well.
However, here is one typical problem I face it every day and I want to check if you have any workaround.
When I work with sqlcmd I always connect via command prompt and whenever I want to check something back in OS, I always have to exit from sqlcmd or I have to open different window.
Is there any trick, which I can use to execute Operating System commands while I am still in sqlcmd prompt?
Indeed a great question, as in my early career I had faced the same issue and I finally figured out the solution.
While we are in the sqlcmd mode at that time we can use !! (Double exclamation marks) to execute Operating System Commands.
Here is the example how you can do the same with the help of command prompt:
Here is the example how you can do the same with the help of SSMS:
First go to SSMS >> Menu >> Query >> SQLCMD mode
Once you enable SQLCMD mode in SSMS you can now execute any SQLCMD command in SSMS New Query Windows. You can also execute OS commands in this window.
If you know any such tricks, please leave a comment and I will publish on the blog with due credit.
Reference: Pinal Dave (http://blog.sqlauthority.com)