0

I have this batch script which runs a SQL script. I need to put today's date in the output file.

I've been told to use $(ESCAPE_DQUOTE(DATE)) but can't get it to work.

My output file still reads:

Test_$(ESCAPE_DQUOTE(DATE)).txt

Here is the script I'm trying:

echo off
sqlcmd -m 1 -S 10.108.96.211\QA832 -U Exception -P Password1 -i E:\KCM_UAT\Exception.sql -o C:\Test_$(ESCAPE_DQUOTE(DATE)).txt  -W -h-1 -s "    "
set /p delExit=Press the ENTER key to exit...:

I have tried escaping ) as mentioned in the comments:

echo off
sqlcmd -m 1 -S 10.108.96.211\QA832 -U Exception -P Password1 -i E:\KCM_UAT\Exception.sql -o C:\Test_$(ESCAPE_DQUOTE(DATE^)^).txt -W -h-1 -s "   "
set /p delExit=Press the ENTER key to exit...:

But the output remains unchanged:

Test_$(ESCAPE_DQUOTE(DATE)).txt

I also tried double quotes on the -o portion

FileName

CODE:

echo off
sqlcmd -m 1 -S 10.108.96.211\QA832 -U Exception -P Password1 -i E:\KCM_UAT\Exception.sql -o "C:\Test_$(ESCAPE_DQUOTE(DATE)).txt" -W -h-1 -s "   "
set /p delExit=Press the ENTER key to exit...:
michael_heath
  • 5,042
  • 2
  • 9
  • 21
tdipl
  • 1
  • 1
  • Try escaping `)` with `^` as `C:\Test_$(ESCAPE_DQUOTE(DATE^)^).txt` or double quoting as `"C:\Test_$(ESCAPE_DQUOTE(DATE)).txt"`. – michael_heath Apr 17 '19 at 06:09
  • [possible duplicate](https://stackoverflow.com/questions/7727114/batch-command-date-and-time-in-file-name/18024049#18024049), I also recommend to read [this answer](https://stackoverflow.com/a/19799236/2152082) – Stephan Apr 17 '19 at 14:30
  • I have added the information from your comments to your question where it belongs and fixed the original code formatting to remove the issues it had, _despite you not providing feedback accordingly_. Please now delete both of your comments, they are no longer required. I also note that you've now used a single `TAB` between the doublequotes as opposed to spaces, is that correct? Finally, did you also try using doublequotes for the `-o` argument?, _also commented by @michaelheath_, if so what happened? if not why? – Compo Apr 17 '19 at 14:31
  • My guess, `sqlcmd` accepts `$(ESCAPE_DQUOTE(DATE))` as literal and does not evaluate it. If so, then you may need to generate a literal date to pass on the command line. – michael_heath Apr 19 '19 at 10:37

0 Answers0