sql语句这样写不行: SqlStr:='select Sum(je) as hjje from qtrg where bh<>''99999'' and bh<>''999999'' and jjqs<='+Combobox2.Text;
但这样写: SqlStr:='select Sum(je) as hjje from qtrg where not exists (select * from qtrg where bh=''99999'' and bh=''999999'') and jjqs<='+Combobox2.Text;
也不行,还是把bh=99999的记录合计进去了,该怎么写?
数据库结构:
id bh xmmc dw sl je dj jjqs shy pgr
0 人工 工天 30 1500 50 2 增加土方 赵春敬
0 人工 工天 99 8910 90 2
0 人工 人工 44 1936 44 3
0 99999 本期金额 元 0 10590 1
0 999999 合计 元 0 21180 1
高手指点,万分感激!!
7 个解决方案
#1
是不是有空格,删除空格再试试。
#2
SqlStr:='select Sum(je) as hjje from qtrg where bh =''99999'' and bh =''999999'' and jjqs <='
你用这个查看看。
#3
SqlStr:='select Sum(je) as hjje from qtrg where not exists (select * from qtrg where bh=''99999'' and bh=''999999'') and jjqs <='+Combobox2.Text;
SqlStr:='select Sum(je) as hjje from qtrg A where bh<>''99999'' and jjqs <='+Combobox2.Text
就行了
另外,子查询这么写就不对,(不是指语法上)
#4
你的不对是什么意思,从你的第一个sql上看,语法没有错
#5
本人SQL遇到問題又不好一眼看出來的,基本上都會用SaveToFile,然後執行試試
#6
楼主还是有空多学习学习sql吧。
#7
SqlStr:='select Sum(je) as hjje from qtrg where not exists (select * from qtrg where bh=''99999'' and bh=''999999'') and jjqs <='+
Combobox2.Text;
红色部分有问题
应该为
SqlStr:='select Sum(je) as hjje from qtrg where not exists (select * from qtrg where bh=''99999'' and bh=''999999'') and jjqs <='+QuotedStr(Combobox2.Text);
红色部分有问题
应该为
SqlStr:='select Sum(je) as hjje from qtrg where not exists (select * from qtrg where bh=''99999'' and bh=''999999'') and jjqs <='+QuotedStr(Combobox2.Text);
#1
是不是有空格,删除空格再试试。
#2
SqlStr:='select Sum(je) as hjje from qtrg where bh =''99999'' and bh =''999999'' and jjqs <='
你用这个查看看。
#3
SqlStr:='select Sum(je) as hjje from qtrg where not exists (select * from qtrg where bh=''99999'' and bh=''999999'') and jjqs <='+Combobox2.Text;
SqlStr:='select Sum(je) as hjje from qtrg A where bh<>''99999'' and jjqs <='+Combobox2.Text
就行了
另外,子查询这么写就不对,(不是指语法上)
#4
你的不对是什么意思,从你的第一个sql上看,语法没有错
#5
本人SQL遇到問題又不好一眼看出來的,基本上都會用SaveToFile,然後執行試試
#6
楼主还是有空多学习学习sql吧。
#7
SqlStr:='select Sum(je) as hjje from qtrg where not exists (select * from qtrg where bh=''99999'' and bh=''999999'') and jjqs <='+
Combobox2.Text;
红色部分有问题
应该为
SqlStr:='select Sum(je) as hjje from qtrg where not exists (select * from qtrg where bh=''99999'' and bh=''999999'') and jjqs <='+QuotedStr(Combobox2.Text);
红色部分有问题
应该为
SqlStr:='select Sum(je) as hjje from qtrg where not exists (select * from qtrg where bh=''99999'' and bh=''999999'') and jjqs <='+QuotedStr(Combobox2.Text);