Sql server 插入名为包含昨天';使用BCP更新日期

Sql server 插入名为包含昨天';使用BCP更新日期,sql-server,windows,batch-file,command-line,bcp,Sql Server,Windows,Batch File,Command Line,Bcp,我有一个BCP命令,它有一个硬编码的文件名ID\u Customer\u 160216.csv。文件名以日期结尾,格式为yymmdd bcp sfnav.dbo.Customer in "C:\Users\TSL\Desktop\TSL Data\ID_Customer_151124.csv" -F2 -c -t "^" -r "\n" -S ftpserver\sqlexpress -U abc -P xyz 我想让它成为动态的:用给定格式的昨天日期替换它。启动Powershell ISE并

我有一个BCP命令,它有一个硬编码的文件名
ID\u Customer\u 160216.csv
。文件名以日期结尾,格式为
yymmdd

bcp sfnav.dbo.Customer in "C:\Users\TSL\Desktop\TSL Data\ID_Customer_151124.csv" -F2 -c -t "^" -r "\n" -S ftpserver\sqlexpress -U abc -P xyz

我想让它成为动态的:用给定格式的昨天日期替换它。

启动Powershell ISE并将以下内容粘贴到中。我想这就是你想要的。。。。?我知道这不是cmd,但无论如何,是时候离开这类事情了;)

稳健的方法:

RunBCP.bat

@echo off

::Creating the VBS code that give yesterday date
echo wscript.echo DateAdd("d", -1, date(^)^)>Day.vbs

::Getting yesterday date with day.vbs
for /f "tokens=1-3 delims=/" %%a in ('cscript //nologo Day.vbs') do set "$date=%%c%%b%%a"
del Day.vbs 2>nul

::setting date to YYMMDD
set "$Date=%$Date:~2%"

::Running BCP with the substitued Date
bcp sfnav.dbo.Customer in "C:\Users\TSL\Desktop\TSL Data\ID_Customer_%$Date%.csv" -F2 -c -t "^" -r "\n" -S ftpserver\sqlexpress -U abc -P xyz

然后您只需运行RunBCP.bat

在哪里运行此命令。。。Windows中的命令行,或通过从Windows中的命令行执行带有存储过程的命令,从SQL Server执行命令
@echo off

::Creating the VBS code that give yesterday date
echo wscript.echo DateAdd("d", -1, date(^)^)>Day.vbs

::Getting yesterday date with day.vbs
for /f "tokens=1-3 delims=/" %%a in ('cscript //nologo Day.vbs') do set "$date=%%c%%b%%a"
del Day.vbs 2>nul

::setting date to YYMMDD
set "$Date=%$Date:~2%"

::Running BCP with the substitued Date
bcp sfnav.dbo.Customer in "C:\Users\TSL\Desktop\TSL Data\ID_Customer_%$Date%.csv" -F2 -c -t "^" -r "\n" -S ftpserver\sqlexpress -U abc -P xyz