INSERT INTO sts_typ (site_cd, sts_typ_cat_cd, sts_typ_typ_cd, sts_typ_desc, audit_user, audit_date)
SELECT cf_site.site_cd, 'PR', 'REJECT', 'Reject status', 'admin', GETDATE()
FROM cf_site
WHERE NOT EXISTS (
    SELECT 1
    FROM sts_typ
    WHERE sts_typ_cat_cd = 'PR' AND sts_typ_typ_cd = 'REJECT' AND sts_typ.site_cd = cf_site.site_cd
);
GO


Insert into pur_sts (		site_cd,			
							pur_sts_st_cat,		
							pur_sts_status,	
							pur_sts_description,			
							pur_sts_status_type,		
							pur_sts_email_flag,		
							pur_sts_disable_flag,
							audit_user,		
							audit_date)
Select						site_cd,	
							'PR', 					
							'REJ', 			
							'REJECT PR', 						
							'REJECT', 	
							'0', 							
							'0',
							'admin',
							Getdate()
From cf_site
Where disable_flag = '0'
And NOT EXISTS (
    SELECT 1
    FROM pur_sts (NOLOCK)
    WHERE pur_sts_st_cat = 'PR' AND pur_sts_status = 'REJ' AND pur_sts_status_type = 'REJECT' and pur_sts.site_cd = cf_site.site_cd
)
GO

Insert into usg_pur (	site_cd,			
						usg_pur_usr_grp,		
						usg_pur_status,		
						usg_pur_list,				
						usg_pur_change,		
						usg_pur_view,
						usg_pur_edit,	
						usg_pur_delete,		
						audit_user,				
						audit_date) 
Select					usr_grp.site_cd,	
						usr_grp_usr_grp,		
						pur_sts_status,			
						'0',								
						'0',							
						NULL,
						NULL,				
						NULL,						
						'admin',			
						getdate()
From	usr_grp (NOLOCK), pur_sts (NOLOCK), cf_site (NOLOCK)
Where	usr_grp.site_cd = pur_sts.site_cd 
And		usr_grp.site_cd = cf_site.site_cd
And		pur_sts.site_cd = cf_site.site_cd
And		pur_sts_status = 'REJ'
And		pur_sts_status_type = 'REJECT'
GO