我要从 table2 中查出id,根据id在 table1中查姓名,该如何实现?
即:
   select name from table1 where id=" select tid from table2 where tdate='''+Formatdatetime('yyyy-mm-dd',mytime)+'''and type='''+ztype+''' " 
正确的语句该如何表达?另外,我要把查找出来的name付值给字符串变量str,该如何付?总不能str:=name吧?
谢谢

解决方案 »

  1.   

    select a.id ,b.name from table2 a left join table1  b on a.id=b.idwhere tdate='''+Formatdatetime('yyyy-mm-dd',mytime)+''' and type='''+ztype+'''  
      

  2.   

    where tdate='''+Formatdatetime('yyyy-mm-dd',mytime)+''' and type='''+ztype+'''  
    ============
    这句顺便说明一下,tdate,type都要表明是哪个表的,即如果tdate是table2得,要写成a.tdate,
    type也类似.但是type好像是关键字。如果是关键字要用中括号[]扩起来
      

  3.   

    我查询出来的值如何付给label1.text 啊?急急急!!!
      

  4.   

    忘了看还有第二个问题了,呵呵比如你用adoquery查出来的str:=adoquery.fieldbyname('name').AsString;
      

  5.   

    label1.caption:=adoquery.fieldbyname('name').AsString;
      

  6.   

    select name from table1 where id in ( select tid from table2 where tdate='''+Formatdatetime('yyyy-mm-dd',mytime)+'''and type='''+ztype+''' )
    呵呵,你自己不是能够写了吗