|
如下的sql语句用union把十个相同的语句组合成一个语句,赋给Query.CommandText还能执行吗
我赋了之后老报各种错误
sql语句如下:
'SELECT t3.*, t4.*' + #13#10 +
' FROM (SELECT SUM(decode(n1, 1, a2, NULL)) "1",' + #13#10 +
' SUM(decode(n1, 2, a2, NULL)) "2",' + #13#10 +
' SUM(decode(n1, 3, a2, NULL)) "3",' + #13#10 +
' SUM(decode(n1, 4, a2, NULL)) "4",' + #13#10 +
' SUM(decode(n1, 5, a2, NULL)) "5",' + #13#10 +
' SUM(decode(n1, 6, a2, NULL)) "6",' + #13#10 +
' SUM(decode(n1, 7, a2, NULL)) "7",' + #13#10 +
' SUM(decode(n1, 8, a2, NULL)) "8",' + #13#10 +
' SUM(decode(n1, 9, a2, NULL)) "9",' + #13#10 +
' SUM(decode(n1, 10, a2, NULL)) "10",' + #13#10 +
' SUM(decode(n1, 11, a2, NULL)) "11",' + #13#10 +
' SUM(decode(n1, 12, a2, NULL)) "12",' + #13#10 +
' SUM(decode(n1, 13, a2, NULL)) "13",' + #13#10 +
' SUM(decode(n1, 14, a2, NULL)) "14",' + #13#10 +
' SUM(decode(n1, 15, a2, NULL)) "15",' + #13#10 +
' SUM(decode(n1, 16, a2, NULL)) "16",' + #13#10 +
' SUM(decode(n1, 17, a2, NULL)) "17",' + #13#10 +
' SUM(decode(n1, 18, a2, NULL)) "18",' + #13#10 +
' SUM(decode(n1, 19, a2, NULL)) "19",' + #13#10 +
' SUM(decode(n1, 20, a2, NULL)) "20",' + #13#10 +
' SUM(decode(n1, 21, a2, NULL)) "21",' + #13#10 +
' SUM(decode(n1, 22, a2, NULL)) "22",' + #13#10 +
' SUM(decode(n1, 23, a2, NULL)) "23",' + #13#10 +
' SUM(decode(n1, 24, a2, NULL)) "24",' + #13#10 +
' SUM(decode(n1, 25, a2, NULL)) "25",' + #13#10 +
' SUM(decode(n1, 26, a2, NULL)) "26",' + #13#10 +
' SUM(decode(n1, 27, a2, NULL)) "27",' + #13#10 +
' SUM(decode(n1, 28, a2, NULL)) "28",' + #13#10 +
' SUM(decode(n1, 29, a2, NULL)) "29",' + #13#10 +
' SUM(decode(n1, 30, a2, NULL)) "30",' + #13#10 +
' SUM(decode(n1, 31, a2, NULL)) "31",' + #13#10 +
' SUM(decode(n1, 32, a2, NULL)) "32",' + #13#10 +
' SUM(decode(n1, 33, a2, NULL)) "33",' + #13#10 +
' SUM(decode(n1, 34, a2, NULL)) "34",' + #13#10 +
' SUM(decode(n1, 35, a2, NULL)) "35",' + #13#10 +
' SUM(decode(n1, 36, a2, NULL)) "36",' + #13#10 +
' SUM(decode(n1, 37, a2, NULL)) "37",' + #13#10 +
' SUM(decode(n1, 38, a2, NULL)) "38",' + #13#10 +
' SUM(decode(n1, 39, a2, NULL)) "39",' + #13#10 +
' SUM(decode(n1, 40, a2, NULL)) "40",' + #13#10 +
' SUM(a2) 合计' + #13#10 +
' FROM (SELECT n1, (a1 - a2) a2' + #13#10 +
' FROM (SELECT ROWNUM n1, a1' + #13#10 +
' FROM (SELECT DISTINCT t1.f_inflexion_value a1' + #13#10 +
' FROM t_pud_track_trend_zys t1' + #13#10 +
' WHERE t1.f_trend_name = ''TS1_TOTAL''' + #13#10 +
' AND t1.f_inflexion_value > 0' + #13#10 +
' AND t1.f_inflexion_time >=' + #13#10 +
' (SELECT MAX(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys' + #13#10 +
' WHERE f_trend_name = ''TS1_TOTAL''' + #13#10 +
' AND f_inflexion_time <=' + #13#10 +
' (SELECT MIN(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys t1' + #13#10 +
' WHERE t1.f_trend_name =' + #13#10 +
' ''TS1_FLUX''' + #13#10 +
' AND t1.f_inflexion_time >=' + #13#10 +
SysUtils.QuotedStr(DStart) + #13#10 +
' AND t1.f_inflexion_time <=' + #13#10 +
SysUtils.QuotedStr(DEnd) + #13#10 +
' AND t1.f_inflexion_value > 0)' + #13#10 +
' AND f_inflexion_value = 0)' + #13#10 +
' AND t1.f_inflexion_time <=' + #13#10 +
' (SELECT MIN(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys' + #13#10 +
' WHERE f_trend_name = ''TS1_TOTAL''' + #13#10 +
' AND f_inflexion_time >' + #13#10 +
' (SELECT MAX(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys' + #13#10 +
' WHERE f_trend_name = ''TS1_TOTAL''' + #13#10 +
' AND f_inflexion_time <=' + #13#10 +
' (SELECT MIN(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys t1' + #13#10 +
' WHERE t1.f_trend_name =' + #13#10 +
' ''TS1_FLUX''' + #13#10 +
' AND t1.f_inflexion_time >=' + #13#10 +
SysUtils.QuotedStr(DStart) + #13#10 +
' AND t1.f_inflexion_time <=' + #13#10 +
SysUtils.QuotedStr(DEnd) + #13#10 +
' AND t1.f_inflexion_value > 0)' + #13#10 +
' AND f_inflexion_value = 0)' + #13#10 +
' AND f_inflexion_value = 0))),' + #13#10 +
' (SELECT ROWNUM n2, a2' + #13#10 +
' FROM (SELECT 0 a2' + #13#10 +
' FROM dual' + #13#10 +
' UNION' + #13#10 +
' SELECT DISTINCT t1.f_inflexion_value a2' + #13#10 +
' FROM t_pud_track_trend_zys t1' + #13#10 +
' WHERE t1.f_trend_name = ''TS1_TOTAL''' + #13#10 +
' AND t1.f_inflexion_value > 0' + #13#10 +
' AND t1.f_inflexion_time >=' + #13#10 +
' (SELECT MAX(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys' + #13#10 +
' WHERE f_trend_name = ''TS1_TOTAL''' + #13#10 +
' AND f_inflexion_time <=' + #13#10 +
' (SELECT MIN(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys t1' + #13#10 +
' WHERE t1.f_trend_name =' + #13#10 +
' ''TS1_FLUX''' + #13#10 +
' AND t1.f_inflexion_time >=' + #13#10 +
SysUtils.QuotedStr(DStart) + #13#10 +
' AND t1.f_inflexion_time <=' + #13#10 +
SysUtils.QuotedStr(DEnd) + #13#10 +
' AND t1.f_inflexion_value > 0)' + #13#10 +
' AND f_inflexion_value = 0)' + #13#10 +
' AND t1.f_inflexion_time <=' + #13#10 +
' (SELECT MIN(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys' + #13#10 +
' WHERE f_trend_name = ''TS1_TOTAL''' + #13#10 +
' AND f_inflexion_time >' + #13#10 +
' (SELECT MAX(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys' + #13#10 +
' WHERE f_trend_name = ''TS1_TOTAL''' + #13#10 +
' AND f_inflexion_time <=' + #13#10 +
' (SELECT MIN(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys t1' + #13#10 +
' WHERE t1.f_trend_name =' + #13#10 +
' ''TS1_FLUX''' + #13#10 +
' AND t1.f_inflexion_time >=' + #13#10 +
SysUtils.QuotedStr(DStart) + #13#10 +
' AND t1.f_inflexion_time <=' + #13#10 +
SysUtils.QuotedStr(DEnd) + #13#10 +
' AND t1.f_inflexion_value > 0)' + #13#10 +
' AND f_inflexion_value = 0)' + #13#10 +
' AND f_inflexion_value = 0)' + #13#10 +
' AND f_inflexion_value <' + #13#10 +
' (SELECT MAX(t1.f_inflexion_value)' + #13#10 +
' FROM t_pud_track_trend_zys t1' + #13#10 +
' WHERE t1.f_trend_name = ''TS1_TOTAL''' + #13#10 +
' AND t1.f_inflexion_value > 0' + #13#10 +
' AND t1.f_inflexion_time >=' + #13#10 +
' (SELECT MAX(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys' + #13#10 +
' WHERE f_trend_name = ''TS1_TOTAL''' + #13#10 +
' AND f_inflexion_time <=' + #13#10 +
' (SELECT MIN(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys t1' + #13#10 +
' WHERE t1.f_trend_name =' + #13#10 +
' ''TS1_FLUX''' + #13#10 +
' AND t1.f_inflexion_time >=' + #13#10 +
SysUtils.QuotedStr(DStart) + #13#10 +
' AND t1.f_inflexion_time <=' + #13#10 +
SysUtils.QuotedStr(DEnd) + #13#10 +
' AND t1.f_inflexion_value > 0)' + #13#10 +
' AND f_inflexion_value = 0)' + #13#10 +
' AND t1.f_inflexion_time <=' + #13#10 +
' (SELECT MIN(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys' + #13#10 +
' WHERE f_trend_name = ''TS1_TOTAL''' + #13#10 +
' AND f_inflexion_time >' + #13#10 +
' (SELECT MAX(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys' + #13#10 +
' WHERE f_trend_name =' + #13#10 +
' ''TS1_TOTAL''' + #13#10 +
' AND f_inflexion_time <=' + #13#10 +
' (SELECT MIN(f_inflexion_time)' + #13#10 +
' FROM t_pud_track_trend_zys t1' + #13#10 +
' WHERE t1.f_trend_name =' + #13#10 +
' ''TS1_FLUX''' + #13#10 +
' AND t1.f_inflexion_time >=' + #13#10 +
SysUtils.QuotedStr(DStart) + #13#10 +
' AND t1.f_inflexion_time <=' + #13#10 +
SysUtils.QuotedStr(DEnd) + #13#10 +
' AND t1.f_inflexion_value > 0)' + #13#10 +
' AND f_inflexion_value = 0)' + #13#10 +
' AND f_inflexion_value = 0))))' + #13#10 +
' WHERE n1 = n2)) t4,' + #13#10 +
' (SELECT t.f_date 日期,' + #13#10 +
' t.f_name 牌号名称,' + #13#10 +
' t.f_opno 批次号,' + #13#10 +
' to_char(to_date(t.f_date || '' '' || t.f_start_h || '':'' ||' + #13#10 +
' t.f_start_m || '':00'',' + #13#10 +
' ''YYYY-MM-DD HH24:MI:SS''),' + #13#10 +
' ''HH24:MI'') 批次开始时间,' + #13#10 +
' to_char(to_date(t.f_date || '' '' || t.f_end_h || '':'' ||' + #13#10 +
' t.f_end_m || '':00'',' + #13#10 +
' ''YYYY-MM-DD HH24:MI:SS''),' + #13#10 +
' ''HH24:MI'') 批次结束时间' + #13#10 +
' FROM t_z2report t' + #13#10 +
' WHERE f_date =''2007/04/12''' + #13#10 +
' AND f_opno = 85) t3'; |
|