我有一个从SQL Developer正确运行的查询,但在尝试将其用作Crystal Reports 2008中带参数的命令文本查询时发生了炸弹。
SELECT *
FROM (SELECT PERSON.DISPLAYNAME AS NAME
, LABOR.LA20 AS LABORRECEMPLOYEENUM
, LABOR.LABORCODE AS PERSONLABORCODE
FROM LABOR
LEFT OUTER JOIN PERSON
ON ( LABOR.LABORCODE = PERSON.PERSONID )
WHERE LABOR.LA20 IS NOT NULL
AND LABOR.ACTIVE = 1
AND PERSON.DISPLAYNAME IS NOT NULL
AND LOWER(PERSON.DISPLAYNAME) NOT LIKE '%kimball%'
AND LOWER(PERSON.DISPLAYNAME) NOT LIKE '%electrico%'
AND LOWER(PERSON.DISPLAYNAME) NOT LIKE '%misc labor cost adj%'
AND LOWER(PERSON.DISPLAYNAME) NOT LIKE '%brossoit'
AND LOWER(PERSON.DISPLAYNAME) NOT LIKE '%brossiot')PERSONINFO
LEFT OUTER JOIN (SELECT *
FROM LABTRANS
WHERE LABTRANS.STARTDATE BETWEEN to_date('03/01/2011', 'mm/dd/yyyy') AND to_date('04/01/2011', 'mm/dd/yyyy')) REDUCEDLABORRANGE
ON ( PERSONINFO.PERSONLABORCODE = REDUCEDLABORRANGE.LABORCODE )
WHERE REDUCEDLABORRANGE.LABORCODE IS NULL;
替换硬编码值:
WHERE LABTRANS.STARTDATE BETWEEN to_date('03/01/2011', 'mm/dd/yyyy') AND to_date('04/01/2011', 'mm/dd/yyyy')
在命令文本中使用Crystal Reports参数。
WHERE LABTRANS.STARTDATE BETWEEN to_date({?BeginDate}, 'mm/dd/yyyy') AND to_date({?EndDate}, 'mm/dd/yyyy')
产生错误:找到了数字所在的非数字字符[数据库供应商代码:1858]
WHERE LABTRANS.STARTDATE BETWEEN to_date('{?BeginDate}', 'mm/dd/yyyy') AND to_date('{?EndDate}', 'mm/dd/yyyy')
产生错误:缺少右括号[数据库供应商代码907]
答案 0 :(得分:3)
当然,在我发布后不久,我找到了答案。
我意识到,我不相信Crystal会提前将日期放在正确的格式中(通常,不相信Crystal Reports是正确的选择)。
以下工作:
WHERE LABTRANS.STARTDATE BETWEEN {?BeginDate} AND {?EndDate}
无需另外格式化日期,因为它们已经采用从Crystal流入Oracle的正确格式。