dm.addQpremoney.Close;
   dm.addQpremoney.SQL.Clear;
   dm.addQpremoney.SQL.Add('select max(jknumberid)  as  ID  from    premoney');
   dm.addQpremoney.SQL.Add('where  inhoscode='''+trim(edit2.Text)+'''');
   dm.addQpremoney.Open;就是当找不到符合条件的记录时,我用showmessage(inttostr(dm.addQpremoney['id'])会出错,但现在我只想用sql语句实现此功能:如果找不到该记录的时候,就把ID的值初始化为“1”,当找到该符合条件的记录时,就取其最大的值,这条语句该怎么写??(注:只能用语句实现可以吗??也就是不用dm.addqpremoney.recordcount 等来判断)

解决方案 »

  1.   

    TRYdm.addQpremoney.SQL.Add('select isnull(max(jknumberid),1)  as  ID  from    premoney');
      

  2.   

    if query1.field[0].asintegr=1 then dosomething
      

  3.   

    btw:
    showmessage(VARtostr(dm.addQpremoney['id'])
      

  4.   

    dm.addQpremoney.SQL.Add('select max(jknumberid)  as  ID  from    premoney');
       dm.addQpremoney.SQL.Add('where  inhoscode='''+trim(edit2.Text)+''' and jknumberid is not null');
    ...if not dm.addQpremoney.fields[0].IsNull then
    showmessage(inttostr(dm.addQpremoney['id'])
      

  5.   

    //这些星星下手真快
    SQL.Add('select isnull(max(jknumberid),1)  as  ID  from    premoney');
      

  6.   

    if not dm.addQpremoney.fields[0].IsNull then
    showmessage(dm.addQpremoney['id'].AsString)
      

  7.   

    dm.addQpremoney.Close;
       dm.addQpremoney.SQL.Clear;
       dm.addQpremoney.SQL.Add('select isnull(max(jknumberid),1)  as  ID  from  premoney');
       dm.addQpremoney.SQL.Add('where  inhoscode='''+trim(edit2.Text)+'''');
       dm.addQpremoney.Open;
       showmessage(inttostr(dm.addQpremoney['id']));
    是这样还不行??是不是在paradox7的数据库那里不支持呢???可能各位大侠都是在
    SQL SERVER里面实现的吧。
      

  8.   

    试试我的,或者:
    dm.addQpremoney.SQL.Add('select max(jknumberid)  as  ID  from    premoney');
       dm.addQpremoney.SQL.Add('where  inhoscode='''+trim(edit2.Text)+''' and jknumberid <> null');
      

  9.   

    我都试了!提示是"capability  not  supported"   好象是paradox7数据库不支持的意思吧!!
      

  10.   

    paradox7????
    估计大家都说的是SQLServer
      

  11.   

    if RowsAffected=0  then//判断上面的SQL有没执行
      ID的值初始化为“1”;
    else
      取其最大的值;