declare @a int,@b int,@c int
select @a=sum(Amount) from stocks where InDate<'2008/9/5'
select @b=sum(TotalPrices) from stocks where InDate>='2008/9/5' and InDate<='2008/9/30'
set @c=@a+@b
select @c
能否将以上SQL语句转换成delphi里面的格式~感谢~
select @a=sum(Amount) from stocks where InDate<'2008/9/5'
select @b=sum(TotalPrices) from stocks where InDate>='2008/9/5' and InDate<='2008/9/30'
set @c=@a+@b
select @c
能否将以上SQL语句转换成delphi里面的格式~感谢~
解决方案 »
- 根据TreeView从表中查询满足条件的记录?高手请进.
- 新手问题:我要使一个TEdit控件变为灰色(不可编辑),应该怎么设置属性?Enable=false和readonly=false都不能变灰
- 用HTTP方式从internet上的某个网站下载文件,如何得到下载的速率(比如 50k/s)?
- 如何将有格式的文字与表格一起存到数据库中??
- 请解释指令含义?
- DBEdit是否存在这样的弊端?
- DBGrid的问题.
- 急,在线求教二个简单DELPHI编程问题,回应给分,是关于数据库存取变量及文本框显示问题.
- 在idtcpserver的execute事件中使用adoquery控件出错
- 关于用Delphi5编写的Web服务器应用程序的问题。
- 数据库查询的问题
- cannot perform this operation on a closed dataset!
a, b, c: Integer; function GetValue(ASQL: string): Integer;
begin
With TADODataSet.Create(nil) do
begin
Connection := YourADOConn;
CommandText := ASQL;
Open;
Result := Fields[0].Value
Free;
end;
end;begin
a := GetValue('select sum(Amount) from stocks where InDate<''2008/9/5''');
b := GetValue('select sum(TotalPrices) from stocks where InDate>=''2008/9/5'' and InDate<=''2008/9/30''');
c := a+b;
ShowMessage(IntToStr(c));
end;
a, b, c: Integer; function GetValue(ASQL: string): Integer;
begin
With TADODataSet.Create(nil) do
begin
Connection := YourADOConn;
CommandText := ASQL;
Open;
Result := Fields[0].Value
Free;
end;
end; begin
a := GetValue('select sum(Amount) from stocks where InDate <''2008/9/5''');
b := GetValue('select sum(TotalPrices) from stocks where InDate>=''2008/9/5'' and InDate <=''2008/9/30''');
c := a+b;
ShowMessage(IntToStr(c));
end;试一下
var
a,b,c: float;
begin
// other code........
adoquery1.sql.txt:= 'select sum(Amount) from stocks where InDate < '''+ the date + '''';
adoquery1.execsql;
a:= adoquery1.Fields.Fields[0].asfloat;
adoquery1.sql.txt:= 'select sum(TotalPrices) from stocks where InDate>= ''' + begin date +
'and InDate<= ''' + end date + '''';
adoquery1.execsql;
b:= adoquery1.Fields.Fields[0].asfloat;
c:= a + b;
adoquery1.free;
end
var
s : widestring;
adoquery1 : tadoquery;
begin
s := ' declare @a int,@b int,@c int'
+ ' select @a=sum(Amount) from stocks where InDate<''2008/9/5'''
+ ' select @b=sum(TotalPrices) from stocks where InDate>=''2008/9/5'' and InDate<=''2008/9/30'''
+ ' set @c=@a+@b'
+ ' select @c';
//自己定义adoquery1 及其连接
with adoquery1 do
begin
sql.Text := s;
open;
showmessage(fields.Fields[0].AsString);
end;
end;
'declare @a int,@b int,@c int'这句的关系,有点郁闷,还是非常感谢~