虽然我完全同意@Steve 关于使用参数化查询的评论,但在这种情况下,我只是建议添加一个适当的 TO_DATE 调用来尝试让您继续前进。尝试这个:
cmd.CommandText = "SELECT 'At CFO Approval ' || count(*) || " &
"' Cheques' || ' of Rs.' || " &
"nvl(to_char(sum(bpv_amt),'9,999,999,999'),0) CFOApp " &
"from check_data where sta_flg = 0 and " &
"TRUNC(bpv_date)=TO_DATE('" & TreeView1.SelectedValue & "', 'DD MON YYYY')"
编辑
添加了 TRUNC() 调用日期比较。
测试如下:
CREATE TABLE CHECK_DATA
(BPV_AMT NUMBER,
STA_FLG NUMBER,
BPV_DATE DATE);
INSERT INTO CHECK_DATA (BPV_AMT, STA_FLG, BPV_DATE) VALUES (100, 0, SYSDATE);
INSERT INTO CHECK_DATA (BPV_AMT, STA_FLG, BPV_DATE) VALUES (200, 0, SYSDATE-1);
INSERT INTO CHECK_DATA (BPV_AMT, STA_FLG, BPV_DATE) VALUES (300, 1, SYSDATE);
INSERT INTO CHECK_DATA (BPV_AMT, STA_FLG, BPV_DATE) VALUES (200, 0, SYSDATE);
现在,执行查询:
SELECT 'At CFO Approval ' || count(*) ||
' Cheques' || ' of Rs.' ||
nvl(to_char(sum(bpv_amt),'9,999,999,999'),0) CFOApp
from check_data
where sta_flg = 0 AND
TRUNC(bpv_date) = TO_DATE('29 Aug 2012', 'DD MON YYYY');
结果是
At CFO Approval 2 Cheques of Rs. 300
分享和享受。