请大家帮忙看一下,这,错在哪里了?

tqtang 2003-07-23 03:40:40
现在有table1,Sid为其主键,Sid长度为9位,现在我要通过query查询tabl1中前6位为Edit1中的值的记录,然后把这些记录写入动态生成的表table2中,我如下写法错误:
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select * ');
query1.SQL.Add('into table2');
query1.SQL.Add('from table1 group by sid');
query1.SQL.Add('where strleft(sid,6)='+edit1.Text +'');
query1.Open;
错误是:table2没有定义。
请问这是为什么?(用的是paradox)
谢谢回答!!
...全文
29 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
vsice 2003-07-23
  • 打赏
  • 举报
回复
试试这个
left()是sql server 里的函数,不知paradox是什么?


query1.close;
query1.sql.clear;
query1.sql('select * into table2 from stdentgrade where tyear='+edit3.text+' and left(sid,6)='''+edit2.text+'''');
query1.open;

tqtang 2003-07-23
  • 打赏
  • 举报
回复
去了group by sid还是不对,
这是为什么?
vsice 2003-07-23
  • 打赏
  • 举报
回复
当然错了,group by 写在 where 前面。

tqtang 2003-07-23
  • 打赏
  • 举报
回复
with query1 do
begin
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('create table table2');
query1.SQL.Add('select * ');
query1.SQL.Add('into table2');
query1.SQL.Add('from studentgrade group by sid');
query1.SQL.Add('where tyear='+edit3.text+'');
query1.SQL.add('and strleft(sid,6)='+edit2.Text +'');
query1.Open;
table1.TableName:=table2.db;
table1.active:=true;
end;
现在还是不对,table2没有定义,大家帮忙,这是为什么?
谢谢!
谷戈 2003-07-23
  • 打赏
  • 举报
回复
先建一个tabel2,再运行。
sduzjw 2003-07-23
  • 打赏
  • 举报
回复
这个在D里面还是第一次见在SQL里用过,
tqtang 2003-07-23
  • 打赏
  • 举报
回复
好像不是空格的原因,我加了,但是不起作用啊!
我在调用table2时,还是说table2没有定义!
比如
table3.tablename:=table2;
是不是我上面的语句些错了?
fansnaf 2003-07-23
  • 打赏
  • 举报
回复
什么数据库?
各个sql间要加空格,

query1.SQL.Add(' into table2 ');
tqtang 2003-07-23
  • 打赏
  • 举报
回复
如果不按上面的写法,有更好的写法吗?

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧