TSQL 从同一个表中的另一行获取信息?
我正在构建一个 TSQL 查询来解析来自 FileZilla 的 FTP 日志。我想知道是否有办法从当前行之前的行获取信息?
例如, 我已经解析出以下过程:“STOR file.exe”
FileZilla 直到下一行才说明 STOR 是否成功。所以我想检查下一行,看看 STOR 是否成功或不成功?
人们也可以尝试多次存储文件,所以我想获取其状态的最新版本。
日志文件中的示例信息:
(000005) 4/10/2010 14:55:30 PM - ftp_login_name (IP Address)> STOR file.exe
(000005) 4/10/2010 14:55:30 PM - ftp_login_name (IP Address)> 150 Opening data for transfer.
(000005) 4/10/2010 14:55:30 PM - ftp_login_name (IP Address)> 226 Transfer OK
我想在查询中添加一列,表明 STOR 成功或不成功。
谢谢!
I am building a TSQL query to parse through a FTP log from FileZilla. I am trying to figure out if there is a way to get information from a line preceding the current one?
For example,
I have parsed out the Following procedure: "STOR file.exe"
With the FileZilla is doesn't say if the STOR wass successful until the next line. So I want to check the next line and see if the STOR was successful or was unsuccessful?
Also people could try to STOR a files multiple times so I want to get the last version of its status.
Example Info from Log file:
(000005) 4/10/2010 14:55:30 PM - ftp_login_name (IP Address)> STOR file.exe
(000005) 4/10/2010 14:55:30 PM - ftp_login_name (IP Address)> 150 Opening data for transfer.
(000005) 4/10/2010 14:55:30 PM - ftp_login_name (IP Address)> 226 Transfer OK
I want to add a column in my query that says that the STOR was successful or unsuccessful.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您已将这些行解析为实际的列,并且您拥有 SQL Server 2005 或更高版本。您可以使用下面的
CROSS APPLY
示例查询(未经测试)。我希望这有帮助。Assuming you have parsed these lines into actual columns, and you have SQL server 2005 or greater. You can use
CROSS APPLY
example query below (untested). I hope this helps.詹姆斯的想法是正确的,尽管如果您的日志日期完全相同,则可能会出现一些问题(从您的样本来看,可能会出现这种情况)。您也许可以添加一个标识列来在插入数据时强制执行订单,然后您可以在标识列上使用 James 的概念。
但更重要的是,TSQL 可能不是该项目的最佳选择,至少它本身不是。虽然可以使用一些技术来使其按顺序迭代,但它不如某些其他语言那么好。您可能需要考虑使用更擅长文本处理和顺序处理数据的工具(例如 Python 或 Perl 甚至 C#)来解析文件。
James has the right idea, though there may be some issues if you ever have log dates that are exactly the same (and from your sample it looks like you might). You may be able to add an identity column to force an order at the time the data is inserted, then you can use James' concept on the identity column.
More than that though, TSQL may not be the best choice for this project, at least not by itself. While there are techniques you can use to make it iterate sequentially, it is not as good for that as certain other languages are. You may want to consider parsing your files in a tool, such as Python or Perl or even C#, that is better at text processing and better at processing data sequentially.