我是使用Business Objects在自由手动SQL中创建报表的最终用户。我在过去的三个小时里一直在处理一些代码并且不断收到错误消息“Missing Right Parenthese”。我已经查看了这段代码,现在我不确定错误是否突出显示,我会看到它请帮忙。代码如下:
SELECT
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts') Project,
nvl(Year1.TotAmt,0) "2007", nvl(Year2.TotAmt,0) "2008", nvl(Year3.TotAmt,0) "2009",
nvl(Year4.TotAmt,0) "2010", nvl(Year5.TotAmt,0) "2011",nvl(Year6.TotAmt,0) "2012",
nvl(Year7.TotAmt,0) "2013"
from payment p,
--- Year 1
(select sum(p.payamount) TotAmt, (usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts') Project,
max(to_char(paydate,'yyyy')) Year
from payment p
where trunc(p.paydate) between @prompt('1.Enter Start Date For Period in FIRST Year','D',,,) and
@prompt('2.Enter End Date For Period in FIRST Year','D',,,) and
p.CLASSCODE NOT IN ('NONGIF', 'PCRED') and
p.usercode1 in ('005','016','021','031','033','041','044')
group by
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts')) Year1,
--- Year 2
(select sum(p.payamount) TotAmt, (usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts') Project,
max(to_char(paydate,'yyyy')) Year
from payment p
where trunc(p.paydate-366) between @prompt('1.Enter Start Date For Period in FIRST Year','D',,,) and
@prompt('2.Enter End Date For Period in FIRST Year','D',,,) and
p.CLASSCODE NOT IN ('NONGIF', 'PCRED') and
p.usercode1 in ('005','016','021','031','033','041','044')
group by
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts')) Year2,
--- Year 3
(select sum(p.payamount) TotAmt, (usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts') Project,
max(to_char(paydate,'yyyy')) Year
from payment p
where trunc(p.paydate-731) between @prompt('1.Enter Start Date For Period in FIRST Year','D',,,) and
@prompt('2.Enter End Date For Period in FIRST Year','D',,,) and
p.CLASSCODE NOT IN ('NONGIF', 'PCRED') and
p.usercode1 in ('005','016','021','031','033','041','044')
group by
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts')) Year3,
--- Year 4
(select sum(p.payamount) TotAmt, (usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts') Project,
max(to_char(paydate,'yyyy')) Year
from payment p
where trunc(p.paydate-1096) between @prompt('1.Enter Start Date For Period in FIRST Year','D',,,) and
@prompt('2.Enter End Date For Period in FIRST Year','D',,,) and
p.CLASSCODE NOT IN ('NONGIF', 'PCRED') and
p.usercode1 in ('005','016','021','031','033','041','044')
group by
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts')) Year4,
--- Year 5
(select sum(p.payamount) TotAmt, (usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts') Project,
max(to_char(paydate,'yyyy')) Year
from payment p
where trunc(p.paydate-1461) between @prompt('1.Enter Start Date For Period in FIRST Year','D',,,) and
@prompt('2.Enter End Date For Period in FIRST Year','D',,,) and
p.CLASSCODE NOT IN ('NONGIF', 'PCRED') and
p.usercode1 in ('005','016','021','031','033','041','044')
group by
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts')) Year5,
--- Year 6
(select sum(p.payamount) TotAmt, (usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts') Project,
max(to_char(paydate,'yyyy')) Year
from payment p
where trunc(p.paydate-1826) between @prompt('1.Enter Start Date For Period in FIRST Year','D',,,) and
@prompt('2.Enter End Date For Period in FIRST Year','D',,,) and
p.CLASSCODE NOT IN ('NONGIF', 'PCRED') and
p.usercode1 in ('005','016','021','031','033','041','044')
group by
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts')) Year6,
--- Year 7
(select sum(p.payamount) TotAmt, (usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts') Project,
max(to_char(paydate,'yyyy')) Year
from payment p
where trunc(p.paydate-2192) between @prompt('1.Enter Start Date For Period in FIRST Year','D',,,) and
@prompt('2.Enter End Date For Period in FIRST Year','D',,,) and
p.CLASSCODE NOT IN ('NONGIF', 'PCRED') and
p.usercode1 in ('005','016','021','031','033','041','044')
group by
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts')) Year7
where p.paydate between to_date ('10/01/2007','mm/dd/yyyy') and
to_date ('12/31/2013','mm/dd/yyyy') and
p.CLASSCODE NOT IN ('NONGIF', 'PCRED') and
p.usercode1 in ('005','016','021','031','033','041','044') and
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts') = Year1.Project(+) and
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts') = Year2.Project(+) and
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts') = Year3.Project(+) and
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts') = Year4.Project(+) and
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts')= Year5.Project(+) and
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts') = Year6.Project(+) and
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts') = Year7.Project(+)
group by
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts'),
Year1.TotAmt, Year2.TotAmt, Year3.TotAmt, Year4.TotAmt, Year5.TotAmt, Year6.TotAmt,Year7.TotAmt
order by
decode(usercode1, '005','Major Gifts','016','Major Gifts','021','Major Gifts','031','Major Gifts',
'033','Major Gifts','041','Major Gifts',
'044','Major Gifts')
答案 0 :(得分:2)
在Year子查询中,代码看起来像(usercode1, ...) Project
。你需要在每个人面前decode
。
顺便说一句,我建议给自己一个文本编辑器(例如gvim)进行括号匹配,以便您可以更轻松地识别这些问题。