NOTE: The #JobIDList temp table actually contains about 67,790 records which is the same amount of records i need to insert into the HS_JOB table and since it won't fit the description box i decided to reduce the amount of values.
The issue is that whenever i run this with Rollback i noticed 28 records are not being accounted for, can someone help tune this query to make sure it inserts everything i need:
if object_id('tempdb..#GroupList') is not null
drop table #GroupList;
create table #GroupList
(
RowNum int identity ,
GROUP_ID int
)
if object_id('tempdb..#JobIDList') is not null
drop table #JobIDList;
create table #JobIDList
(
RowNum int identity ,
JOB_ID int
)
if object_id('tempdb..#JobList') is not null
drop table #JobList;
create table #JobList
(
JOB_NAME varchar (64),
EXT_REF int,
SHORT_NAME varchar (4),
PAY_RATE smallmoney
)
if object_id('tempdb..#GroupJobList') is not null
drop table #GroupJobList;
create table #GroupJobList
(
RowNum int identity ,
GROUP_ID int,
JOB_NAME varchar (64),
EXT_REF int,
SHORT_NAME varchar (4),
PAY_RATE smallmoney
)
insert into #GroupList (GROUP_ID)
select distinct GROUP_ID
from Inf.Organization_Detail_Denorm
where COMPANY_XR = 263043
and GROUP_ID not in (281001535)
set @GroupCount = (select count(*)
from #GroupList)
insert into #JobList (JOB_NAME, EXT_REF, SHORT_NAME, PAY_RATE)
values
('Back Of House','BOH - Primary 1','-1','BOH1','0'),
('Back Of House','BOH - Primary 2','-1','BOH2','0'),
('Back Of House','BOH - Primary 3','-1','BOH3','0'),
('Back Of House','BOH - Primary 4','-1','BOH4','0'),
('Back Of House','BOH - Primary 5','-1','BOH5','0'),
('Back Of House','BOH - Secondary 1','-1','BOHS','0'),
('Back Of House','BOH - Secondary 2','-1','BOHS','0'),
('Back Of House','BOH - Secondary 3','-1','BOHS','0'),
('Front Of House','Bagger 1','-1','BAG1','0'),
('Front Of House','Bagger 2','-1','BAG2','0'),
('Front Of House','Bagger 3','-1','BAG3','0'),
('Front Of House','Runner 1','-1','RUN1','0'),
('Front Of House','Runner 2','-1','RUN2','0'),
('Front Of House','Runner 3','-1','RUN3','0'),
('Front Of House','Upstream Order Taker','-1','UOT','0'),
('Front Of House','Register','-1','REG','0'),
('Front Of House','Outside Payment','-1','OP','0'),
('Front Of House','Drive-Thru Expeditor','-1','DTE','0'),
('Front Of House','Drive-Thru Stager','-1','DTS','0'),
('Front Of House','Drive-Thru Primary Drinks','-1','DTPD','0'),
('Front Of House','Drive-Thru Secondary Drinks','-1','DTSD','0'),
('Front Of House','Desserts','-1','DSRT','0'),
('Front Of House','Mobile Drinks','-1','MD','0'),
('Front Of House','Front Counter Stager','-1','FCS','0'),
('Front Of House','Front Counter Expeditor','-1','FCE','0'),
('Front Of House','Stuffer','-1','STF','0'),
('Front Of House','IPOS 1','-1','IPOS','0'),
('Front Of House','IPOS 2','-1','IPOS','0'),
('Front Of House','IPOS 3','-1','IPOS','0'),
('Front Of House','IPOS 4','-1','IPOS','0')
insert into #GroupJobList (GROUP_ID, JOB_NAME, EXT_REF, SHORT_NAME, PAY_RATE)
select g.GROUP_ID, j.JOB_NAME, j.EXT_REF, j.SHORT_NAME, j.PAY_RATE
from #JobList j
cross join #GroupList g
insert into #JobIDList (JOB_ID)
values
('1089651792'),
('1089651793'),
('1089651794'),
('1089651795'),
('1089651796'),
('1089651797'),
('1089651798'),
('1089651799'),
('1089651800'),
('1089651801'),
('1089651802'),
('1089651803'),
('1089651804'),
('1089651805'),
('1089651806'),
('1089651807'),
('1089651808'),
('1089651809'),
('1089651810'),
('1089651811')
--------------------------------------------------
raiserror('Insert into Front of House', 0, 1) with nowait;
insert into hs.HS_JOB (ID, ORG_ID, JOB_NAME, PAY_RATE, OT_TYPE, OT_VALUE, EXTERNAL_REF, SORT_ORDER, DISABLED, DEFAULT_SCHEDULE_ID, SHORT_NAME,
HSC_PAYRATE_EXCLUDE, IS_BLENDED, SHARED_REF, LAST_EDITED_BY, LAST_EDITED_DATE_TIME)
select i.JOB_ID, j.GROUP_ID, j.JOB_NAME, j.PAY_RATE, 1, 1.50, j.EXT_REF, 0, 0, [login to view URL], j.SHORT_NAME, 0, 0, null, null, null
from #GroupJobList j
join #JobIDList i
on [login to view URL] = [login to view URL]
join hs.HS_ROLE r
on j.GROUP_ID = r.ORG_ID
where r.ROLE_NAME = [login to view URL]
and r.ROLE_NAME in ('Front of House')
set @RowsAffected = @@rowcount
raiserror('Updated %d FOH Rows', 0, 1, @RowsAffected) with nowait;
--------------------------------------------------
raiserror('Insert into Back of House', 0, 1) with nowait;
insert into hs.HS_JOB (ID, ORG_ID, JOB_NAME, PAY_RATE, OT_TYPE, OT_VALUE, EXTERNAL_REF, SORT_ORDER, DISABLED, DEFAULT_SCHEDULE_ID, SHORT_NAME,
HSC_PAYRATE_EXCLUDE, IS_BLENDED, SHARED_REF, LAST_EDITED_BY, LAST_EDITED_DATE_TIME)
select i.JOB_ID, j.GROUP_ID, j.JOB_NAME, j.PAY_RATE, 1, 1.50, j.EXT_REF, 0, 0, [login to view URL], j.SHORT_NAME, 0, 0, null, null, null
from #GroupJobList j
join #JobIDList i
on [login to view URL] = [login to view URL]
join hs.HS_ROLE r
on j.GROUP_ID = r.ORG_ID
where r.ROLE_NAME = [login to view URL]
and r.ROLE_NAME in ('Back of House')
set @RowsAffected = @@rowcount
raiserror('Updated %d BOH Rows', 0, 1, @RowsAffected) with nowait;
rollback tran--commit