日期:2014-05-17  浏览次数:20561 次

表复制求助
CREATE TABLE [dbo].[PART_PROCESS](
[ID] [int] IDENTITY(1,1) NOT NULL,
[PARTID] [int] NOT NULL,
[STEPID] [int] NOT NULL,
[PROCESSID] [int] NOT NULL,
[SINGLETIME] [float] NULL,
[INSTID] [int] NULL,
[PROCEPROGRAM] [nvarchar](max) NULL,
[INSTUSETIME] [float] NULL,
[CHANGEPARTTIME] [float] NULL,
[ORDERNO] [float] NOT NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[PARTS](
[ID] [int] IDENTITY(1,1) NOT NULL,
[CODE] [nvarchar](max) NOT NULL,
[NAME] [nvarchar](max) NOT NULL,
[SPECIFICATION] [nvarchar](max) NOT NULL,
[DESCRIBE] [nvarchar](max) NULL
) ON [PRIMARY]

insert into parts(CODE,NAME,SPECIFICATION,DESCRIBE)values('200018','电磁铁','V5210.2-03','')
insert into parts(CODE,NAME,SPECIFICATION,DESCRIBE)values('200070','电磁铁','V5110.2-03','')
insert into PART_PROCESS(PARTID,STEPID,PROCESSID,SINGLETIME,INSTID,PROCEPROGRAM,INSTUSETIME,CHANGEPARTTIME,ORDERNO)values
('1','37','43','19','19','','0','7','5')
insert into PART_PROCESS(PARTID,STEPID,PROCESSID,SINGLETIME,INSTID,PROCEPROGRAM,INSTUSETIME,CHANGEPARTTIME,ORDERNO)values
('1','27','40','10','32','','0','7','2')
insert into PART_PROCESS(PARTID,STEPID,PROCESSID,SINGLETIME,INSTID,PROCEPROGRAM,INSTUSETIME,CHANGEPARTTIME,ORDERNO)values
('1','28','41','15','19','','0','7','3')
insert into PART_PROCESS(PARTID,STEPID,PROCESSID,SINGLETIME,INSTID,PROCEPROGRAM,INSTUSETIME,CHANGEPARTTIME,ORDERNO)values
('1','29','42','10','34','','0','7','4')
insert into PART_PROCESS(PARTID,STEPID,PROCESSID,SINGLETIME,INSTID,PROCEPROGRAM,INSTUSETIME,CHANGEPARTTIME,ORDERNO)values
('1','30','14','26','15','','0','0','1')[/size]

比如我现在查询
select parts.ID FROM parts where  parts.name like '%电磁铁%'
会出来结果
1
2
我希望能够实现一个复制功能,把PARTID=1的在PART_PROCESS表里面内容复制一遍,但是PARTID改成2.也就是说2在PART_PROCESS表里面的数据等于物料ID1在PART_PROCESS表里面的数据.
语句在执行时,我可以手工指定匹配字段'电磁铁'但是物料2或者物料34等要自动出来。因为实际会有很多。
在线等
------最佳解决方案--------------------
INSERT INTO PART_PROCESS(partid,STEPID,PROCESSID,SINGLETIME,INSTID,PROCEPROGRAM,INSTUSETIME,CHANGEPARTTIME,ORDERNO)
 SELECT  b.id partid,STEPID,PROCESSID,SINGLETIME,INSTID,PROCEPROGRAM,INSTUSETIME,CHANGEPARTTIME,ORDERNO
 FROM PART_PROCESS a INNER JOIN  parts b ON A.id<>b.id AND b.id<>1
 WHERE partid=1  AND b.NAME LIKE '%电磁铁%'

根据你的数据改了一下.
------其他解决方案--------------------
INSERT INTO PART_PROCESS(partid,STEPID,PROCESSID,SINGLETIME,INSTID,PROCEPROGRAM,INSTUSETIME,CHANGEPARTTIME,ORDERNO)
SELECT 2 partid,STEPID,PROCESSID,SINGLETIME,INSTID,PROCEPROGRAM,INSTUSETIME,CHANGEPARTTIME,ORDERNO
FROM PART_PROCESS WHERE partid=1

------其他解决方案--------------------
引用:
SQL code123INSERT INTO PART_PROCESS(partid,STEPID,PROCESSID,SINGLETIME,INSTID,PROCEPROGRAM,INSTUSETIME,CHANGEPARTTIME,ORDERNO)SELECT 2 partid,STEPID,PROCESSID,SINGLETIME,INSTID,PROCEPROGR……

多谢,但是2是查询出来,因为实际会有很多,
------其他解决方案--------------------
你的那个要求其实我看了4、5遍,还是不是很清楚,要不你直接用文字来说说:你想要什么?
------其他解决方案--------------------