(产品具体信息表)pros            字段 id  sortid(所属小类的ID值)  content
(产品小类信息表)pros_smallsort  字段 id  bigsortid(所属大类的ID值)  sort
(产品大类信息表)pros_bigsort   字段  id                          bigsort现在执行一个操作,在有大类别 ID 值bid的情况下,删除大类,同时要求删出此大类下的小类及小类下的产品我这样想的,先删除大类
CONN.execute("delete *from pros_bigsort where id="&bid)用联合查询删除产品记录
conn.execute("delete *from pros where sortid in(select * from pros_smallsort where bigsortid="&bid)  删除小类记录
conn.execute("delete *from pros_smallsort where bigsortid="&bid)运行出错,提示Microsoft JET Database Engine (0x80040E14)
丢失 ), ], 或项目 在查询表达式 'sortid in(select * from pros_smallsort where bigsortid=103' 中。
/admin_admin/admin/pros/delsort.asp, 第 19 行
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--当引用FCK时候,第一句话必须存在,以免数据显示乱码!-->
<!--#include file="../conn.asp"-->
<%bid=request.QueryString("id")
conn.execute("delete * from pros_bigsort where id="&bid)conn.execute("delete *from pros where sortid in(select * from pros_smallsort where bigsortid="&bid)
conn.execute("delete * from pros_smallsort where bigsortid="&bid)
%>
看来是联合查询删除产品表中记录时候出现问题,请问这句该如何写呢,谢谢了!在线等

解决方案 »

  1.   

    这种需求一般都是用触发器或者级联来做.有关级联则参考:/*
    标题:两表通过字段关联进行级联删除。
    作者:爱新觉罗·毓华(十八年风雨,守得冰山雪莲花开) 
    时间:2008-11-20
    地点:广东深圳
    */create table ta(id int not null)
    create table tb(id int , aid int)
    insert into ta values(1)
    insert into ta values(2)
    insert into tb values(1 , 1)
    insert into tb values(2 , 2)
    insert into tb values(3 , 1)
    go--一、查看原始数据
    --ta表的原始数据
    select * from ta
    /*
    id          
    ----------- 
    1
    2
    */
    --tb表的原始数据
    select * from tb
    /*
    id          aid         
    ----------- ----------- 
    1           1
    2           2
    3           1
    */--二、看看没有创建级联删除时的情况(删除ta表id=1的数据,看看是否影响tb表)
    delete from ta where id = 1
    select * from ta
    /*
    id          
    ----------- 
    2
    */
    select * from tb
    /*
    id          aid         
    ----------- ----------- 
    1           1
    2           2
    3           1
    */--三、恢复原始数据,创建级联删除,删除ta表id=1的数据,看看是否影响tb表
    insert into ta values(1)
    --为ta创建主健
    alter table ta add constraint pk_ta_id primary key (id)
    go
    --为tb创建外健,并指定级联删除
    alter table tb add constraint fk_tb_aid foreign key (aid) references ta(id) on delete cascade
    go
    delete from ta where id = 1
    select * from ta
    /*
    id          
    ----------- 
    2
    */
    select * from tb
    /*
    id          aid         
    ----------- ----------- 
    2           2
    */--删除级联约束
    alter table tb drop constraint fk_tb_aid
    go
    --删除测试表
    drop table ta , tb
    go
      

  2.   

    conn.execute("delete *from pros where sortid in(select * from pros_smallsort where bigsortid="&bid)
    改成对应的字段试下
      

  3.   

    如果是用触发器则参考:create trigger pros_bigsort_trig on pros_bigsort for delete
    as
    delete from pros_smallsort where bigsortid = (select bigsort from deleted)
    go
    create trigger pros_smallsort_trig on pros_smallsort for delete
    as
    delete from pros where sortid = (select id from deleted)
    go
      

  4.   


    conn.execute("delete *from pros where sortid in(select * from pros_smallsort where bigsortid="&bid)
    改成对应的字段试下
    select * from pros_smallsort where bigsortid="&bid
    返回的字段应该不止一个
    所以会报错
    改成对应字段
      

  5.   

    sortid in(select sortid from pros_smallsort where bigsortid=103' 不是*
      

  6.   

    conn.execute("delete *from pros where sortid in(select * from pros_smallsort where bigsortid="&bid&")")
    少一扩号
      

  7.   

    还有提醒楼主 注意看错误提示,下面已经说出来了"丢失 ), ]," :运行出错,提示Microsoft JET Database Engine (0x80040E14)
    丢失 ), ], 或项目 在查询表达式 'sortid in(select * from pros_smallsort where bigsortid=103' 中。
    /admin_admin/admin/pros/delsort.asp, 第 19 行
      

  8.   

    -------------------
    conn.execute("delete *from pros where sortid in(select id from pros_smallsort where bigsortid="&bid))语句未结束
    /admin_admin/admin/pros/delsort.asp, line 19, column 100
    conn.execute("delete *from pros where sortid in(select id from pros_smallsort where bigsortid="&bid))
    --------------------
    conn.execute("delete *from pros where sortid in(select id from pros_smallsort where bigsortid="&bid&")")Microsoft JET Database Engine (0x80040E07)
    标准表达式中数据类型不匹配。
    /admin_admin/admin/pros/delsort.asp, 第 19 行
      

  9.   

    sortid与ID类型不匹配
    还是bigsortid与="&bid 不匹配
    检查下看看
      

  10.   

    conn.execute("delete *from pros where sortid in(select id from pros_smallsort where bigsortid="&bid&")")
    这样就OK了bigsortid建表时候是文本型,bid得到的是int型,把字段属性修改一下,现在好了鸣谢:
    sql_sf
    dawugui
    xys_777
    bancxc
    谢谢以上各位,也谢谢其它热心的朋友!