June 30, 2015

Segmented Data Exports to Text Files of Specified Format in esProc



Below is a selection from a database table, TB1:

Based on this data, you need to generate text files of the specified format and with the following names (yyyyMMddHH) by the hour.
2011101106.txt
1|2011-10-11 6:24:21|aaa
2|2011-10-11 6:30:45|dddd

2011101107.txt
3|2011/10/11 7:10:12|dsf
4|2011/10/11 7:50:38|dffew
5|2011/10/11 7:59:59|dfae

2011101108.txt
6|2011/10/11 8:00:00|edfae

After grouping data by the hour, you export every group to a text file according to the specified format (|) and name it after the hour: 

A1: Use a SQL to create a database cursor sorted by CreateTime. db represents the connection to a database.
A2-B2: Group data by CreateTime (yyyyMMddHH), and fetch data by loop, one group each time, to export, through B2, to text files named after the create time. And specifiy format for the text data at the same time.

Text files are as follows: