在如今各式各样的数据库中,对时间类型的数据处理也不尽相同。要将FineReport中的时间类型数据与数据库中的时间类型数据对接,必须借助一些格式转换函数。
在此,以常用的数据库Oracle和SQL Server为例,举例讲述其与FineReport之间时间类型的转换,同FR使用者们共同交流。
Oracle and FineReport
例如:
Oracle数据库中有名为example的数据表,表中有名为Date的时间字段,FineReport中有一个时间参数a;现要求选出example表中Date字段与参数a相等的记录。
分情况转换方法如下表所示:
Oracle |
FineReport |
SQL语法 |
日期类型字段 Date(yyyy-MM-dd) |
时间类型参数a /字符串类型参数a |
Select * from example where Date=to_date('${a}','yyyy-MM-dd') |
字符串类型字段 Date(MM/dd/yyyy) |
时间类型参数a /字符串类型参数a |
Select * from example where Date=to_char('${a}','MM/dd/yyyy') |
时间类型字段 Date(yyyy MM dd hh24:mi:ss) / (yyyy MM dd hh12:mi:ss) |
时间类型参数a /字符串类型参数a |
Select * from example where Date=to_char('${a}','yyyy MM dd hh24:mi:ss') / Select * from example where Date=to_char('${a}','yyyy MM dd hh12:mi:ss') |
字符串类型字段 Date(yyyy.MM.dd hh24:mi:ss) / (yyyy.MM.dd hh12:mi:ss) |
时间类型参数a /字符串类型参数a |
Select * from example where Date=to_char('${a}','yyyy.MM.dd hh24:mi:ss') / Select * from example where Date=to_char('${a}','yyyy.MM.dd hh12:mi:ss') |
SQL Server and FineReport
例如:
Oracle数据库中有名为example的数据表,表中有名为Date的时间字段,FineReport中有一个时间参数a;现要求选出example表中Date字段与参数a相等的记录。(SQL Server中对不同的时间格式都有对应的不同公式写法)
日期参数对应关系如下表所示:
SQL Server |
FineReport |
SQL语法 |
Date (mon dd yyyy hh:miAM/ PM) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 0) / Select * from example where Date= CONVERT(varchar(100), ${a}, 100) |
Date(mm/dd/yy) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 1) |
Date(yy.mm.dd) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 2) |
Date(dd/mm/yy) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 3) |
Date(dd.mm.yy) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 4) |
Date(dd-mm-yy) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 5) |
Date(dd mon yy) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 6) |
Date(mon dd, yy) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 7) |
Date(hh:mm:ss) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 8) / Select * from example where Date=CONVERT(varchar(100), ${a}, 108) |
Date (mon dd yyyy hh:mi:ss:mmmAM/ PM) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 9) / Select * from example where Date=CONVERT(varchar(100), ${a}, 109) |
Date(mm-dd-yy) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 10) |
Date(yy/mm/dd) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 11) |
Date(yymmdd) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 12) |
Date (dd mon yyyy hh:mm:ss:mmm(24h)) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 13) / Select * from example where Date=CONVERT(varchar(100), ${a}, 113) |
Date(hh:mi:ss:mmm(24h)) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 14) / Select * from example where Date=CONVERT(varchar(100), ${a}, 114) |
Date (yyyy-mm-dd hh:mm:ss[.fff]) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 20) / Select * from example where Date=CONVERT(varchar(100), ${a}, 120) |
Date (yyyy-mm-dd hh:mm:ss[.fff]) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 21) / Select * from example where Date=CONVERT(varchar(100), ${a}, 121) |
Date(mm/dd/yyyy) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 101) |
Date(yyyy.mm.dd) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 102) |
Date(dd/mm/yyyy) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 103) |
Date(dd.mm.yyyy) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 104) |
Date(dd-mm-yyyy) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 105) |
Date(dd mon yyyy) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 106) |
Date(Mon dd, yyyy) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 107) |
Date(mm-dd-yyyy) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 110) |
Date(yyyy/mm/dd) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 111) |
Date(yyyymmdd) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 112) |
Date (yyyy-mm-ddThh:mi:ss.mmm (no spaces)) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 126) |
Date (yyyy-mm-ddThh:mi:ss.mmmZ (no spaces)) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 127) |
Date (dd mon yyyy hh:mi:ss:mmmAM) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 130) |
Date (dd/mm/yy hh:mi:ss:mmmAM) |
时间类型参数a / 字符串类型参数a |
Select * from example where Date=CONVERT(varchar(100), ${a}, 131) |