Posted this yesterday. Received some help that initially worked. Now the problem is back. Don't understand what SQL could be doing to cause this.I receive a primary key constraint violation when running the following insert:INSERT INTO MLFML (BOOK_QTY, CREATED_BY, DATE_CREATED, DATE_LAST_ACT, DATE_LAST_ISSUE, DATE_LAST_PHY, DATE_LAST_PRINT, DATE_LAST_RECPT, MLFML_USER_1, MLFML_USER_2, MLFML_USER_3, MLFML_USER_4, ON_HAND_QTY, OPERATOR_ID, PART_ID, PHYSICAL_QTY, STOCK_LOCATION, STORES_CODE, DATE_LAST_UPDT, TIME_LAST_UPDT, DELETE_FLAG) SELECT 0, 'SYS.DM', GETDATE(), @TODAY, NULL, @TODAY, NULL, @TODAY, 0, 0, '', '', PI.QUANTITY, 'SYS.DM', PI.PART_ID, 0, PI.TO_LOCATION, PI.STORES_CODE, convert(char(11),getdate(),101), convert(char(5),getdate(),108), 'N'FROM PISTOCKTRANSFER PIWHERE NOT EXISTS (SELECT 1 FROM MLFML WHERE (STORES_CODE = PI.STORES_CODE) AND (PART_ID = PI.PART_ID) AND (STOCK_LOCATION = PI.TO_LOCATION))
I use the following to validate what records should be inserting.SELECT * FROM PISTOCKTRANSFER PI WHERE NOT EXISTS(SELECT 1 FROM MLFML WHERE (STORES_CODE = PI.STORES_CODE) AND (PART_ID = PI.PART_ID) AND (STOCK_LOCATION = PI.TO_LOCATION))
There are 21 records that should be loaded. Each record is unique in the PISTOCKTRANSFER table, based off of the primary key in the MLFML table which is STORES_CODE, PART_ID and STOCK_LOCATION. The above SELECT statement returns back 21 records just as I would expect. But for some reason they won't load using the INSERT above. There is an Identity key, (not part of the Primary Key), but that should get updated automatically.Any help would be greatly appreciated.