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里面的格式~感谢~
解决方案 »
- TString怎么增加上一个string?
- 各位大侠救救偶!
- 问个简单的问题,如何删除listview中指定的行?
- 这里有谁懂DELPHI的???请教
- 请问delphi编译后的程序有没有debug版和relase版的区别?
- 欢迎访问 Grid++Report 的网站:www.GridppReport.com。一个可以丢开显示网格(各种Grid)做出整个报表系统的构件,非常适合制作动态报表,
- 请问Delphi怎样从Excel中提取数据?
- 关于声明变量的地点
- 为什么屏幕总是跳.关不了窗体?
- 救命啊,又要不及格了!!!
- 数据库查询的问题
- 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'这句的关系,有点郁闷,还是非常感谢~