我的 SQL 插入/选择有问题。
INSERT INTO TBLPMHISTORY(RELEQUIPMENTID,DTETHISPMDUE,STRCAMPUS,STRROOM)
(SELECT INTEQUIPMENTID,DTEPMDATENEXTDUE,STRCAMPUS,STRROOM
FROM TBLEQUIPMENT
WHERE DTEPMDATENEXTDUE BETWEEN GETDATE() AND DATEADD("DAY",21,GETDATE()))
它似乎只在新表中插入一行,但是当我自己运行语句的 SELECT 部分时,它返回 84 行。
我不确定是否有限制批量插入的东西,但任何帮助将不胜感激。
创建 PMHISTORY 表的代码如下:
CREATE TABLE TBLPMHISTORY(
INTPMHISTORYID INT NOT NULL PRIMARY KEY IDENTITY,
RELEQUIPMENTID INT NOT NULL FOREIGN KEY REFERENCES TBLEQUIPMENT(INTEQUIPMENTID),
STRDESCRIPTION VARCHAR(64) DEFAULT 'Preventative Maintenance',
DTETHISPMDUE DATETIME,
YSNPMDONE BIT DEFAULT '0',
YSNPMCONVERTEDTOJOB BIT DEFAULT '0',
INTRELATEDJOBNUMBER INT DEFAULT '0',
STRCAMPUS VARCHAR(30),
STRROOM VARCHAR(30))
CREATE UNIQUE NONCLUSTERED INDEX [IX_PMHistory_DTETHISPMDUE] ON TBLPMHISTORY( DTETHISPMDUE) WITH (IGNORE_DUP_KEY = ON) ON [PRIMARY]