一、  
with datamodule1.ADOQuery1 do
    begin
      close;
      sql.Clear;
      sql.Add('select count(*) as lcount from TableInformation1');
      sql.Add('where tablenum='''+trim(edit1.text)+'''');
      prepared:=true;
      execsql;
    end;  if datamodule1.ADOQuery1.FieldValues['lcount']=0 then
     //判断是否有编号为edit1.text的数据记录
    begin
    ....
    end;
我在编译时可以运行,但功能不能实现,请问有什么更好的办法!
二、判断数据库中某个编号的数据记录的results字段(char)为'入库'
  我先
var 
   aresrlt:string;    
begin
.......
    begin
      close;
      sql.Clear;
      sql.Add('select results from TableInformation2 where tablenum='''+trim(edit1.Text)+'''');
      prepared:=true;
      open;
    end;
  aresult:=':results';
    if aresult='入库' then
  .....
end;
请问有什么更好的吗?

解决方案 »

  1.   

    2.这个已经是很简单的查询了,没有必要有更好的方法吧?不过,一般是将results='入库'作为查询条件放在select语句里面,看返回是否为eof
      

  2.   

    我想请教第一个问题,关于LCOUNT的,谢谢
      

  3.   

    if exsits(select 1 from table1 where ....) select 1
      

  4.   

    如果是SQLServer,用它的Exists
      

  5.   

    只是判断是否有记录的话,用Count(*)还不如用Top 1,判断Query.IsEmpty就行了.
      

  6.   

    可以用Count(1),最好你第一列是自增的ID,有索引更快
      

  7.   

    谢谢,请问如果用top怎么编写,我是菜鸟,没用过TOP,能不能给个例子,thank,thank
      

  8.   

    select top 1 * from ......你这里没有必要了,你在查询条件里面加上and results='入库',然后直接看记录是否eof
      

  9.   

    with datamodule1.ADOQuery1 do
        begin
          close;
          sql.Clear;
          sql.Add('select count(*) as lcount from TableInformation1');
          sql.Add('where tablenum='''+trim(edit1.text)+'''');
          prepared:=true;
          execsql;
        end;if  lcount>1 then
        showmessage( '重复');
      

  10.   

    select top 1 * from TableName
      

  11.   

    如果是ORACLE的话就是 
    select * from Tablename where rownum<=1 如果是SQL SERVER 就是
    select top 1 * from TableName
      

  12.   

    F1按到F9
    一、
    with datamodule1.ADOQuery1 do
    begin
    close;
    sql.Clear;
    sql.Add('select count(*) as lcount from TableInformation1');
    sql.Add('where tablenum='''+trim(edit1.text)+'''');
    prepared:=true;
    execsql;//--->>Open
    end;