Sqlcmd .bat file sql output with date append


Sqlcmd .bat file sql output with date append



I have a .bat file that I have scheduled to run daily at 1am using task scheduler on a windows server 2008 r2. The final output file gets overwritten every time so I need to add a date after the output file name.



Here is the code in .bat file :


code


.bat


SQLCMD -S ServerName -d DbName-E -i C:locscript.sql -o C:locscriptOutputtemp.txt -s"|" -W
findstr /B /V /C:"----" "C:locscriptOutputtemp.txt" > "C:locfinaloutput.txt"
del "C:locscriptOutputtemp.txt"



I tried to add %date% like "C:locfinaloutput%date%.txt" but then nothing gets generated as output. It's my first time creating this so any guidance will be helpful.


%date%


"C:locfinaloutput%date%.txt"



Thank you!





Possible duplicate of How do I get current datetime on the Windows command line, in a suitable format for using in a filename?
– Squashman
Jun 29 at 18:38





Solution in this thread worked! :) Someone please mark this as an answer. Thank you! stackoverflow.com/questions/9074407/…
– sky_limit
Jun 29 at 19:02






Delete your question then as you can see it is a duplicate.
– Squashman
Jun 29 at 19:05





I don't think it's a duplicate. This thread will help other users since it has additional information where the code is deleting "----".
– sky_limit
Jun 29 at 19:15





Perhaps this question, addresses the dashed line issue!
– Compo
Jun 30 at 12:07









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV