Append multiplying generated records

mikke3141

New member
Local time
Today, 23:24
Joined
Oct 24, 2019
Messages
8
Hi,

I'm trying to insert into my headcount table new persons with the following code.

Code:
INSERT INTO HeadCountTbl (HeadCount, EmpID, Month_ID )
SELECT 1, HeadCountTbl.EmpID, HeadCountTbl.Month_ID
FROM MonthTbl INNER JOIN HeadCountTbl ON MonthTbl.ID = HeadCountTbl.Month_ID
WHERE (((HeadCountTbl.EmpID)=123) AND ((MonthTbl.Month)=201905));

The month information is coming from another linked table. Now each time I run the code it doubles the amount of records appended. First time it adds one person, second time the same person twice and third time four times. Is there a way to fix the SQL so that it generates only one line to the table?
 
Hi. What happens if you don't join the month table with the head count table?
 
Hi,

Then the Month_ID field in the headcount table becomes blank.

Mikke
 

Users who are viewing this thread

Back
Top Bottom