Link to home
Start Free TrialLog in
Avatar of dtolo
dtolo

asked on

trigger error

Avatar of dtolo
dtolo

ASKER

When I go to create this triger

CREATE TRIGGER Employee_Trg_Ins
ON Employee
FOR INSERT
AS
INSERT INTO Collect
SELECT EmployeeNumber
FROM inserted
WHERE NOT EXISTS (
    SELECT 1
    FROM Collect
    WHERE Collect.EmployeeNumber = inserted.EmployeeNumber )

I get an error: 213 : insert error column name or number of supplied values does not match table definition
Avatar of dtolo

ASKER

Also, could someone please answer this part?

How do I set the delete to happen every other week with no human intervention?  Would that be a job in enterprise Manager?
ASKER CERTIFIED SOLUTION
Avatar of ShogunWade
ShogunWade

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
part 2 about the delete.    Yes to perform a scheduled activity of any sort you should use SQL Server Agent.   Create a job and specify the DLEETE statement and the schedule.
Avatar of dtolo

ASKER

Thank you shogun!!
I'm not really big SQL guy yet... but I was thinking about

"while" loop and have "wait" command for 1 day (I think 1 day is maximum) and add each day until it reaches 7th and then do your thing... but the only problem I think about is that, how long does SQL variable last...?   :)
no worries,  we were all beginners @ some stage.     the while and wait method will also work and in some cases ive used this myself, but only when ive wanted more specific scheduleing functionality than is available in sql server agent.  eg: Every time the british summer time starts or ends for example.    the down side to while and wait is that you need to invoke it when sql starts up by configuring autorun stored procs,  and also you end up having to write all the logging stuff :(.

Anyway  glad i could help.
Avatar of dtolo

ASKER

on this

 DELETE FROM Collect LEFT JOIN
                      Employee ON collect.EmployeeNumber = employee.EmployeeNumber
WHERE     employee.EmployeeNumber IS NULL

I get incorrect syntax near key word left
Hey, dtolo, sorry I dropped out for awhile. Looks like you got most everything going with others helping.

There are several ways to restructure the delete query, here's one using aliases for the table names:

DELETE c
FROM Collect c LEFT JOIN
          Employee e ON c.EmployeeNumber = e.EmployeeNumber
WHERE     e.EmployeeNumber IS NULL

(This gets rid of any records in Collect that do not have a matching EmployeeNumber in the Employee table.)
Avatar of dtolo

ASKER

Thanks JD :-)