Hi, I have a very large table - Table1
I am trying to have a temporary Global table , which contains the subset of the large table. But the insertion of data from Table1 to Global table is taking a longer time. I do not have access to run the sql execution plan / create index. The Table1 does not contain a IDENTITY column, but has another column as Primary key.
Below is the code which I am trying:
create table session.##change_criteria(CHANGE_DATE_FROM DATE not null, CHANGE_DATE_TO DATE not null)
insert into session.##change_criteria values ('2020-09-21','2020-09-28')
create TABLE session.##new_changes ( Test_ID integer not null, TestName char(15) not null )
insert into session.##new_changes select Test_ID, TestName from TABLE1 with (nolock)
where CAST(CREATION as date) >= (select CHANGE_DATE_FROM from session.##change_criteria) and
CAST(CREATION as date) <= (select CHANGE_DATE_TO from session.##change_criteria) or
CAST(RECONDT as date) >= (select CHANGE_DATE_FROM from session.##change_criteria) and
CAST(RECONDT as date) <= (select CHANGE_DATE_TO from session.##change_criteria)
The last insert is causing performance issues, to insert a weeks data alone , it is taking more than 2.5 hours. The first 3 statements do not take any time, only the last insert is having the issues.
How to fix this?

