var
SQLName:String;
SQLName:=Format('%.6D',[1001]);  //001001SQLSent:='Select * from Sysobjects where name='''+NewTable+'''';            //SQL.Open 没有问题
SQLSent:='Create table '''+NewTable+'''(P_Code decimal(12,5) not null)';    //ExecSQL 提示001001附近语法出错
请教,问题出在哪里?是单引号使用得不对吗?

解决方案 »

  1.   

    最好不要这么来构造sql语句。首先能用参数解决的用参数方式来解决,实在不能用参数的,尝试用format。这样的构造方式很容易在引号上出问题。而且也容易出现注入问题。
      

  2.   

    调试的时候可以在execsql或者open之前用showmessage看看sql语句,然后放在查询分析器里面执行一下看能不能通过。
      

  3.   

    SQLSent:= 'Create   table   ' ' '+NewTable+ ' ' '(P_Code   decimal(12,5)   not   null) ';
    改成
    SQLSent:= 'Create   table   '+NewTable+  '(P_Code   decimal(12,5)   not   null) ';
    多了一个引号
      

  4.   

    抱歉
    两句语句的内容中NewTable改成SQLName
    发帖没看清楚,但是怎么编辑不了?
    今天继续测试时,发现在SQLName前加个字符D 以D001001为table name就没问题了。不过怕理解有误,望各位指点。
      

  5.   

    SQLName:=Format('[%.6D]',[1001]);     //001001 
      

  6.   

    这种写法容易产生错误(引号不对或者是该有空格的地方没有加空格),建议使用Formatvar 
      SQLName:String; SQLName := Format('%.6D', [1001]);
    SQLSent := Format('Create Table %s(P_Code decimal(12, 5) not null)', [SQLName]);
      

  7.   

    to sung001 
     表名不能以数字开头,确定吗?