table1
      字段:u_empid   char(1),
          u_edate    datetime
table2
      字段:u_empid   char(1),
          u_edate    datetime語句一:
刪除語句:delete 表1
        where 表1.u_edate is null and 表2.u_edate is not null
語句二:
插入語句insert into 表1 (u_empid,u_edate) values ('..','..')
       ( where 表1.u_empid 不存在 and 表2.u_empid 存在 and 表1.u_edate is null)這個單純的語句能實現不?

解决方案 »

  1.   

    1delete a from table1 a,table2 b where a.u_empid=b.u_empid and a.u_edate is null and b.u_edate is not null
      

  2.   

    两个表以什么关联? u_empid么?delete from [表1] where [表1].u_edate is null and u_empid in (select u_empid  from [表2] where [表2].u_edate is not null )
      

  3.   

    第二个好像逻辑上有问题,
    表1不存在的,那么肯定表1的日期为空啥..
    insert into [表1] select * from [表2] where u_empid not in (select u_empid from [表1])
      

  4.   

    更新一下。抱歉
    table1 
          字段:u_empid  char(1), 
              u_edate    datetime 
    table2 
          字段:u_empid  char(1)語句一: 
    刪除語句:delete 表2 
            where 表1.u_edate is not null and 表2.u_empid 存在
    語句二: 
    插入語句insert into 表2 (u_empid,u_edate) values ('..','..') 
          ( where 表1.u_empid 存在 and 表2.u_empid 不存在 and 表1.u_edate is null) 這個單純的語句能實現不?
             
      

  5.   

    頂﹐瞬間分沒了﹐雖然我更新的慢了點﹐但是你的意思我收下了﹐等哈給分﹐先測試一下...
    sql小白飛過
      

  6.   

    就是SQL學的不穩當,測試后你的數據可行﹐但是我把database的特定數據刪除了
    又要去插入﹐昏迷了
      

  7.   

    insert into [表1] select * from [表2] where u_empid not in (select u_empid from [表1])這個好像不行哦
      

  8.   

    有啥问题,
    表结构不一样的话才有问题,
    栏位不一样,所以会出错,加上栏位就正确了.insert into [表1] values(u_empid) select u_empid from [表2] where u_empid not in (select u_empid from [表1])
    --or
    insert into [表1] values(u_empid,u_edate) select u_empid ,getdate() from [表2] where u_empid not in (select u_empid from [表1])
      

  9.   

    delete a from table1 a,table2 b where a.u_empid=b.u_empid and a.u_edate is null and b.u_edate is not null再加個條件呢
    table1.u_empid 存在 and table2.u_empid 不存在
      

  10.   

    你的insert 只能插入一行﹐看來我還是得麻煩點﹐先找出要插入得u_empid 再循環插入了等會給兩位分﹐語句小弟收下了﹐非常感謝。潛水寫后台去﹐等會再來看了
      

  11.   

    insert into aa values(u_empid) select u_empid from bb where u_empid not in (select u_empid from aa)values(u_empid)???這個內容中不允許有名稱 "u_empid"。有效的運算式包括常數、常數運算式及 (某些內容中) 變數。不允許使用資料行名稱。
      

  12.   

    哈哈﹐你也出小錯誤呢﹐為什么你一定要加values(u_empid)
    而不是insert into aa (u_empid)呢?