从完整文件路径中删除时间部分
假设完整文件路径存储在名为的变量中@[User::FilePath]
您必须添加一个字符串类型的变量(例如:@[User::Filename]
), 数据流任务之前add an Expression Task
并使用以下表达式:
@[User::Filename] = SUBSTRING(@[User::FilePath], 1, LEN(@[User::FilePath]) -
FINDSTRING(REVERSE(@[User::FilePath]), "\\", 1)) + "\\" +
LEFT(TOKEN(@[User::FilePath],"\\",TOKENCOUNT(@[User::FilePath],"\\")),
LEN(TOKEN(@[User::FilePath],"\\",TOKENCOUNT(@[User::FilePath],"\\"))) - 10) + ".txt"
Example:
如果值@[User::FilePath]
is
C:\新文件夹\1\Filename_20190503001221.txt
Then @[User::Filename]
将:
C:\新文件夹\1\Filename_20190503.txt
如果您只有文件名
文件名_20190503001221.txt
并且文件夹路径存储在另一个变量中,只需使用以下表达式:
@[User::Filename] = @[User::Folderpath] + "\\" +
LEFT(TOKEN(@[User::FilePath],"\\",TOKENCOUNT(@[User::FilePath],"\\")),
LEN(TOKEN(@[User::FilePath],"\\",TOKENCOUNT(@[User::FilePath],"\\"))) - 10) + ".txt"
从变量读取文件源
Click on the flat file connection manager used to read the source file, press F4 to show the properties tab, Click on the expression property and assign the following expression to the connectionstring
property:
@[User::Filename]
现在改变数据流任务 Delay validation
财产价值为True
.
- SQL Server Integration Services 中的动态平面文件连接 https://www.mssqltips.com/sqlservertip/1084/dynamic-flat-file-connections-in-sql-server-integration-services/