Append multiplying generated records (1 Viewer)

mikke3141

New member
Local time
Today, 14: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?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:24
Joined
Oct 29, 2018
Messages
21,357
Hi. What happens if you don't join the month table with the head count table?
 

mikke3141

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

Then the Month_ID field in the headcount table becomes blank.

Mikke
 

Users who are viewing this thread

Top Bottom