在程序中写SQL语句 select max(code) from table10 where ...
code是 sql server里的 varchar 类型(是纯数字但位数太长 故用字符型)
怎么取max的返回值 
var iCount :integer
iCount:=Adoquery1.field[0].asinteger 为何不行?(类型不配?)
该怎么取?????
 如果没有符合的条件的记录

if *..recordcount = 0 then
icount;=0
又为什么不被执行?

解决方案 »

  1.   

    select max(code) as maxcode from table10 where...iCount:=AdoQuery1.FieldByName('maxcode').AsInteger;
      

  2.   

    select max(code) as 最大值 from table10 where ..
    iCount:=AdoQuery1.FieldByName('最大值 ').AsInteger;
      

  3.   

    用recordcount返回记录数很不保险,你可以设置断点,它的值很可能为-1,所以不执行if
    试试select max(code) from table10 where ...
    var iCount :string
    iCount:=Adoquery1.field[0].asstring
      

  4.   

    select max(code) as maxcode from table10 where...
    if not(ADOQuery.IsEmpty) then
      iCount:=AdoQuery1.FieldByName('maxcode').AsInteger;
      

  5.   

    在下认为这是因为你的数值太大了,导致Asinteger出了错,你可以用
    showmessage(AdoQuery1.fields.field[0].asstring);
    来看看返回的字符串值是什么。
      

  6.   

    谢谢大家 pazee(耙子)(三个代表)  的方法 通过了