有关SQL的问题,为什么同样的一句话,"select * from sysobjects where type = 'U'"在SQL Analyer 中运行正常,在delphi中运行就报错。
'Invalid field name.[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'U'.

解决方案 »

  1.   

    type为SQL的保留字。
    你可以试试这样:
    adoquery1.SQL.Add('select * from sysobjects where [type]='+QuotedStr('U'));
      

  2.   

    没看到源程序,不过小心单引号。例:
    var sqlstring:WideString;sqlstring := 'Select * from sysobjects where type = ''U''';在字符串中连续两个单引号算一个。
      

  3.   

    In Delphi:
    Sql.add('select * from sysobjects where type = ' + '''' + 'U + ''''');
      

  4.   

    在使用数据库的时候,表名,字段名一定不要与保留字重复.
    QuotedStr适合过滤的转换函数.
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Query1.Close;
      Query1.SQL.Text:='select * from sysobjects where type = ''U''';
      Query1.Open;
    end;
    你可能什么地方不对,如上代码调试通过~!
      

  6.   

    为什么在delphi执行name字段没有显示出来,而我在sql analyer里是可以显示的。
      

  7.   

    有这么怪吗?你Select Name as PName ...........试试================================================================
         ◆◆◆ CSDN查询助手,查询方便快捷◆◆◆ 下载地址:  
     http://CoolSlob.ifood1.com/Download/CSDNFinder.exe  
     http://CoolSlob.8u8.com/Download/Tools/CSDNFinder.Slob[更名为.exe即可]  
      

  8.   

    执行了Select Name as PName ...........结果是什么也没有。空的记录。
      

  9.   

    h_huajun(阿华)说的是正确的!
    你可以查一下 DataSet.Filter 的用法,里面就用到了QuotedStr()这个函数。