0

我有这样的 SSIS 变量表达式,

@[System::PackageName]+","+    
@[System::SourceName]+","+    
(DT_STR,15,1252) @[System::ErrorCode]+","+    
@[System::ErrorDescription]+","+    
(RIGHT((DT_WSTR,4)
DATEPART("yyyy",GetDate()),4)+"/"+    
RIGHT("0"+(DT_WSTR , 2)
 DATEPART("mm", GetDate()),2)+"/"+    
RIGHT("0"+(DT_WSTR,2)
DATEPART("dd",GetDate()),2)+"_"+    
RIGHT("0"+(DT_WSTR,2)
DATEPART("HH",GetDate()),2)+":"+    
RIGHT("0"+(DT_WSTR,2)
DATEPART("MM",GetDate()),2)+":"+    
RIGHT("0"+(DT_WSTR,2)
DATEPART("SS",GetDate()),2))+","+
 @[System::MachineName]

现在我想从中获取一些@[System::ErrorDescription]位于之前的字符串,这是值at的示例@[System::ErrorDescription]

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\blablablabl\yes.txt'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver) at System.Threading.CompressedStack.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)

我所做的是在我的变量表达式上编写子字符串代码:

SUBSTRING(@[System::ErrorDescription], 1, FINDSTRING(@[System::ErrorDescription], "at", 1)-1)+","+

但它总是给我一个错误,那个子字符串值不能为负,我的代码有什么问题?

4

1 回答 1

0

如果 的结果FINDSTRING(@[System::ErrorDescription], "at", 1)为零(即未找到字符串),则子字符串表达式的最后一个参数变为-1. 这是一个常见的问题。

也许您可以尝试评估它是否为零,如果不是,则仅使用 Findstring。为了清楚起见,我已经拆分了下面的表达式,但它应该都在一行上。我没有要测试的 SSIS,但看看它是否有效。

我不认为你已经发布了你的完整表达,但这应该给你的想法。

FINDSTRING(@[System::ErrorDescription], "at", 1)==0
   ?
"Nothing Found"
   :
SUBSTRING(
    @[System::ErrorDescription], 
    1, 
    FINDSTRING(@[System::ErrorDescription], "at", 1)-1
)

这是一个描述条件的链接:

http://msdn.microsoft.com/en-us/library/ms141680.aspx

我不相信这是完整的故事,但试试吧,它会冲掉你的下一个问题。

于 2013-03-25T05:18:45.340 回答