I am trying to build a stored proc which will terminate all active employees from the selected Job BUT
Not from the selected Departments.
So the user goes through this task from the front-end and selects the JobDescription, DepartmentDescription
and a Date. When this task finishes the user hits the finish button which executes a stored proc. Since
the selected DepartmentCodes or JobCodes are more than one, I am running into issues. So eventually
instead of building an execute statement with one parameter, it builds a long one with all the Department
codes selected...which of course is wrong because the sp does not accept that many params. How should
I do it? This is how my sp looks:
Any help is greatly appreciated. Thanks in advance.
CREATE PROCEDURE [dbo].[MassTermination]
@EffectiveDate datetime,
@JobCode varchar,
@DepartmentCode varchar,
@TerminationReasonCode varchar
AS
SET NOCOUNT ON
CREATE TABLE #PersonTemp
(PersonGUID uniqueidentifier NOT NULL)
INSERT INTO #PersonTemp
SELECT Distinct tsh.PersonGUID
FROM TableStatusHistory tsh, TableJobHistory tjh, TableLocationHistory tlh
WHERE tsh.PersonGUID = tjh.PersonGUID
AND tsh.PersonGUID = tlh.PersonGUID
AND tsh.StatusCurrentFlag = 1
AND JobCode = @JobCode
AND DepartmentCode != @DepartmentCode
INSERT INTO TableStatusHistory
(PersonGUID,
StatusStartDate,
StatusCode
)
SELECT
u.PersonGUID,
@EffectiveDate,
'TERMINATED'
FROM TableStatusHistory s
INNER JOIN #PersonTemp u ON s.PersonGUID = u.PersonGUID WHERE s.LocationCurrentFlag = 1
Not from the selected Departments.
So the user goes through this task from the front-end and selects the JobDescription, DepartmentDescription
and a Date. When this task finishes the user hits the finish button which executes a stored proc. Since
the selected DepartmentCodes or JobCodes are more than one, I am running into issues. So eventually
instead of building an execute statement with one parameter, it builds a long one with all the Department
codes selected...which of course is wrong because the sp does not accept that many params. How should
I do it? This is how my sp looks:
Any help is greatly appreciated. Thanks in advance.
CREATE PROCEDURE [dbo].[MassTermination]
@EffectiveDate datetime,
@JobCode varchar,
@DepartmentCode varchar,
@TerminationReasonCode varchar
AS
SET NOCOUNT ON
CREATE TABLE #PersonTemp
(PersonGUID uniqueidentifier NOT NULL)
INSERT INTO #PersonTemp
SELECT Distinct tsh.PersonGUID
FROM TableStatusHistory tsh, TableJobHistory tjh, TableLocationHistory tlh
WHERE tsh.PersonGUID = tjh.PersonGUID
AND tsh.PersonGUID = tlh.PersonGUID
AND tsh.StatusCurrentFlag = 1
AND JobCode = @JobCode
AND DepartmentCode != @DepartmentCode
INSERT INTO TableStatusHistory
(PersonGUID,
StatusStartDate,
StatusCode
)
SELECT
u.PersonGUID,
@EffectiveDate,
'TERMINATED'
FROM TableStatusHistory s
INNER JOIN #PersonTemp u ON s.PersonGUID = u.PersonGUID WHERE s.LocationCurrentFlag = 1