Monday 25 January 2016

Command Prompt : PAUSE keyword usage in BATCH file and Redirect output to File.


When we create batch file to execute SQL Commands using sqlcmd utility (or) to execute SSIS packages using DTEXEC utility, we knew that once the execution is over, black screen (CMD prompt screen) will flash off within a sec.

We often more interested in seeing the output status of the execution(successful or failed because of any reasons) once it is done.

All we need to achieve the same is by using the PAUSE keyword at last in the batch file.

PAUSE keyword ensures control gets back to the user by prompting a message
"Press any key to continue . . ." .
In this case after user hits any key in the keyboard only CMD prompt will goes off.

1)using SQLCMD

sqlcmd ....................
PAUSE

(or)

2)using DTEXEC

DTEXEC
PAUSE

Note: PAUSE keword is case insensitive.

3) Create or OverWrite

If you want to redirect the output status to any file, you can use > (Greater than) operator followed by filepath with filename.


sqlcmd .................................. > "C:\Users\TEST\output.txt"
PAUSE

Note: File will be created if not exists. File content will be overriden if file with the same name already exists.

4) Append
If you want to append use >> operator.



sqlcmd .................................. >> "C:\Users\TEST\output.txt"
PAUSE

Tuesday 5 January 2016

Extract text from image

Is there a way to copy out or grab the text content from Image?

Answer is YES.

Sometimes i do get images wherein SQL queries(with complicated join conditions and respective aliases appended column output list)exist which i need to type it out in SSMS.

Traditional way of doing this is "keep both the windows(Image and SSMS) side and side and kick start the boredom work(type till you lasts your energy)".

Easy way of doing the same is by using Microsoft OneNote (one among application in Microsoft bundle listed along with Word, Excel, Outlook etc)

OneNote supports Optical Character Recognition (OCR).

To extract text from a picture:

1) Copy and Paste the image in OneNnote (or) Use "File->Open options" to bring the image to OneNote editor.

2) Right-click the picture, and click Copy Text from Picture

3) Click where you’d like to paste the copied text, and then press Ctrl+V.