Please see the DDL below:
CREATE TABLE [dbo].[TBX_RRDGenieDeletedItem](
[DeletedId] [decimal](25, 0) NOT NULL
) ON [PRIMARY]
INSERT INTO TBX_RRDGenieDeletedItem values (90309955000010401948421)
CREATE TABLE [dbo].[dbNicheCIS](
[OccurrenceID] [decimal](25, 0) NULL,
[OccurrenceFileNo] [varchar](20) NULL
)
INSERT INTO dbNicheCIS values (90309955000010401948421,'3212')
CREATE TABLE [dbo].[Asset_Table](
[user_crimenumber] [varchar](4000) NOT NULL
)
INSERT INTO Asset_Table VALUES ('3212; 4512; 34322; 45674; 33221')
The only table I designed was dbNicheCIS. I am trying to find all of the rows in tbx_rrdgeniedeleteditem that are also in Asset_Table
using the LIKE
statement. Asset_Table
contains the OccurrenceFileNo
(note that asset table contains occurrencefileno: 3212, which relates to OccurrenceID: 90309955000010401948421)
. I have tried this:
Select user_crimenumber from tbx_rrdgeniedeleteditem --asset_table.user_crimenumber
inner join dbNicheCIS on tbx_rrdgeniedeleteditem.deletedid = dbNicheCIS.OccurrenceID
cross join asset_table
where deletedid like '903%' and asset_table.user_crimenumber like '%' + occurrencefileno + '%'
It works, but it takes hours to run. Is there a better way to approach it rather than a cross join?