set sql_flow="select Id,',',ApplierName,',',FlowStatus,',',IsApproved,',',CreateTime from *** where ***"
set sql_device="select deviceName,',',business,',',username,',',deviceMac,',',createtime,',',enabledflag from *"
set user=sa
set pwd=pwd
set server=ip
set year=%date:~0,4%
set month=%date:~5,2%
set day=%date:~8,2%
set hour=%time:~0,2%
set min=%time:~3,2%
set second=%time:~6,2%
bcp %sql_flow% queryout "C:\流程单-%year%-%month%-%day% %hour%-%min%-%second%.txt" -c -U %user% -P %pwd% -S %server%
copy "C:\流程单Header.txt" + "C:\流程单-%year%-%month%-%day% %hour%-%min%-%second%.txt" "C:\流程单-%year%-%month%-%day% %hour%-%min%-%second%.csv"/Y
bcp %sql_device% queryout "C:\设备-%year%-%month%-%day% %hour%-%min%-%second%.txt" -c -U %user% -P %pwd% -S %server%
copy "C:\设备单Header.txt" + "C:\设备-%year%-%month%-%day% %hour%-%min%-%second%.txt" "C:\设备-%year%-%month%-%day% %hour%-%min%-%second%.csv"/Y
pause
注意:
1.只有安装mssql 客户端才能使用bcp命令
2.把上述文件存成.bat命令即可