with TADOQuery.Create(self) do
begin
Connection := DataModuleMain.ADOConnection;
SQL.Clear;
SQL.Add('Insert Into SB_T_Electric_Revenue(Corporation_ID,Year, Item_ID)');
SQL.Add('Select ' + QuotedStr(g_s_Corporation_ID));
SQL.Add(', ''' + QuotedStr(EditYear.Text) + ', Item_ID');
SQL.Add('From SB_T_Electric_Item_Set');
SQL.Add('Where Item_Type_Code=' + QuotedStr('1'));
SQL.Add('Order By Order_ID;');
try
ExecSQL;
finally
Free;
end;为什么提示Insert Into语句语法错误???(数据库为Access,把该语句直接在Delphi的SQL Expolrer中执行没问题,是不是在Delphi中不支持在Select中带变更或常量值,因为我如果只在Select中取Item_ID字段值,则不会提示语法错误)
begin
Connection := DataModuleMain.ADOConnection;
SQL.Clear;
SQL.Add('Insert Into SB_T_Electric_Revenue(Corporation_ID,Year, Item_ID)');
SQL.Add('Select ' + QuotedStr(g_s_Corporation_ID));
SQL.Add(', ''' + QuotedStr(EditYear.Text) + ', Item_ID');
SQL.Add('From SB_T_Electric_Item_Set');
SQL.Add('Where Item_Type_Code=' + QuotedStr('1'));
SQL.Add('Order By Order_ID;');
try
ExecSQL;
finally
Free;
end;为什么提示Insert Into语句语法错误???(数据库为Access,把该语句直接在Delphi的SQL Expolrer中执行没问题,是不是在Delphi中不支持在Select中带变更或常量值,因为我如果只在Select中取Item_ID字段值,则不会提示语法错误)
SQL.Add(', ''' + QuotedStr(EditYear.Text) + ', Item_ID ');
SQL.Add(' From SB_T_Electric_Item_Set');
SQL.Add(' Where Item_Type_Code=' + QuotedStr('1'));
SQL.Add(' Order By Order_ID;');请注意换行时在关键字前加上空格
否则关键字会与前面的内容练成一个字符串
当然就出错了
var
strsql :string;strsql := 'Insert Into SB_T_Electric_Revenue(Corporation_ID,Year, Item_ID)......';
sql.add(strsql);这样可以showmessage(strsql)就可以看看是什么错误了
Select '123123'
,'2004', Item_ID
From SB_T_Electric_Item_Set
Where Item_Type_Code='1'
Order By Order_ID;
写错了,应该是:SQL.Add(', ' + QuotedStr(EditYear.Text) + ', Item_ID');
但错误依旧, lufancy(聆雨)所说的并没用
你最好换成变量形式的
var
strsql :string;strsql := 'Insert Into SB_T_Electric_Revenue(Corporation_ID,Year, Item_ID)......';
sql.add(strsql);
应该就没问题啦,试试把!!!!
SQL.Add(Format('Select %s ' ,[g_s_Corporation_ID]));
下边仿照此写法
若你的语句没错,肯定行的
insert into test(id,year) value(:id,:year)在Access中会把Year当作Acces的Year涵数
改成insert into test(id,[year]) value(:id,:year)问题解决