I am trying to run a SQL Query through Batch File and when I am trying to do so I am getting
invalid argument error
@echo ------BILLING REPORT---------
@echo Please enter billing report Date in (YYYY/MM/DD)
::set /P D = Enter Date:
::Date %Date% > Billing_Data.sql
sqlcmd -S database\instance_name -E -i "C:\Users\rb54761\Deskto\rb54761\Billing_Data_For_Certs_New.sql" > Output.txt -v Date = '2016-07-01'
:: -o "C:\Users\rb54761\Desktop\rb54761\Output.txt"
COPY C:\Users\rb54761\Desktop\rb54761\Output.txt C:\Users\rb54761\Desktop
DateCompleted > CONVERT(DATETIME, '$(Date)', 102))
In you command line you use
-v Date = '2016-07-01', and the single quotes are considered part of the sqlcmd variable. In your script you use
'$(Date)', which becomes
''2016-07-01'', and the error should be fairly obvious.
Remove one set of quotes from either the command line or the script, and all should work.
If you want to quote the value in the command line to protect against poison characters or to include batch token delimiters like space or comma, then you must use double quotes: something like
-v var = "Some value with spaces". In this case, the double quotes are not included in the value.