有三张表如下如示
表A
DeviceNO       DeviceID    ApplyUseID  ApplyReturnID
-------------- ----------- ----------- -------------
表B
ApplyID    DeviceID    DeviceName   DeviceNum   DeviceNO          
---------- ------     -------------  ------ ------------------
5407       6           高端配置       1         AA0001
5407       7           低端配置       1         BB0001,BB0002
5407       37          高端配置       1           
表C
DeviceNO    DeviceName    
----------- --------------
AA0001      高配置笔记本  
AA0002      低配置笔记本  
BB0001      高配置台式机  
BB0002      低配置台式机  
CC0001      彩色打印机    
CC0002      一般打印机    
现要(做复制操作)将B,C表之间有关联的数据插入A表中 注意(B表中 DeviceNO 列数据是不固定的) 如下所示DeviceNO       DeviceID    ApplyUseID  ApplyReturnID
-------------- ----------- ----------- -------------
AA0001         6             5407        null
BB0001          7             5407       null
BB0002          7             5407        null

解决方案 »

  1.   

    --查詢
    Select
    C.DeviceNO,
    B.DeviceID,
    B.ApplyID As ApplyUseID,
    null As ApplyReturnID
    From
    B
    Inner Join
    C
    On CharIndex(C.DeviceNO, B.DeviceNO) > 0
      

  2.   

    --插入
    Insert 

    Select
    C.DeviceNO,
    B.DeviceID,
    B.ApplyID As ApplyUseID,
    null As ApplyReturnID
    From
    B
    Inner Join
    C
    On CharIndex(C.DeviceNO, B.DeviceNO) > 0
      

  3.   

    Or--查詢
    Select
    C.DeviceNO,
    B.DeviceID,
    B.ApplyID As ApplyUseID,
    null As ApplyReturnID
    From
    B
    Inner Join
    C
    On B.DeviceNO Like '%' + C.DeviceNO + '%'--插入
    Insert 

    Select
    C.DeviceNO,
    B.DeviceID,
    B.ApplyID As ApplyUseID,
    null As ApplyReturnID
    From
    B
    Inner Join
    C
    On B.DeviceNO Like '%' + C.DeviceNO + '%'