Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

declare @companyId int =1446

DECLARE @temp2 TABLE(company_id INT,SYSPOSITIONID INT)


INSERT INTO @temp2
SELECT
tct.company_id,tct.SYSPOSITIONID
FROM
TBL_CC21_STAFF_POSITION tct
WHERE tct.SYSPOSITIONID NOT IN
(
SELECT DISTINCT ccl.POSITION
FROM tbl_cc21_classroom_teachers ccl
WHERE
ccl.company_id = @companyId
and user_status=1
) AND company_id = @companyId

DELETE sp
FROM TBL_CC21_STAFF_POSITION sp
WHERE EXISTS (SELECT *
FROM @temp2 pcd
WHERE sp.syspositionid=pcd.SYSPOSITIONID and
sp.COMPANY_ID=pcd.company_id
)

You might also like