我正在运行一个批处理文件

时间:2019-05-22 16:02:35

标签: batch-file sqlcmd

我正在运行一个创建CSV文件的批处理文件,该文件从数据库中获取数据,但是生成的CSV文件以空白行开头,这导致了一些问题。  有什么办法可以修改我的bat文件以不创建此额外的空白行?

@echo Off
set qty=-1

:loop4weekends
set "separator1=-"
set "separator2=_"
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,now)
echo>>"%temp%\%~n0.vbs" d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
echo>>"%temp%\%~n0.vbs"         right(100+month(s),2)^&_
echo>>"%temp%\%~n0.vbs"         right(100+day(s),2)^&_
echo>>"%temp%\%~n0.vbs"         d
for /f %%a in ('cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
del "%temp%\%~n0.vbs"
endlocal& set "YY=%result:~0,4%" & set "MM=%result:~4,2%" & set "DD=%result:~6,2%" & set "daynum=%result:~-1%"
:: if the daynum is a weekend then loop to get the Friday
set "weekend="
if %daynum% EQU 1 set weekend=1&set "qty=-3"
if %daynum% EQU 7 set weekend=1&set "qty=-2"
if defined weekend goto :loop4weekends
set "day=%YY%%separator1%%MM%%separator1%%DD%"
set "day1=%YY%%separator2%%MM%%separator2%%DD%"

sqlcmd  -E -S %MachineIP% -Q "exec T_StoreProcedure @companyFundIDs=N'',@inputDate=N'%RESULT1%' "  -d %ClientDB% -o "DAVIDCAPITAL_EOD_%rdate%.csv" -s"," -W

ECHO CSV file has been generated successfully
pause

0 个答案:

没有答案