I need to search a table for multiple phone numbers that are from an external source. Because the formatting in the table is not strict (1234567 or 123-4567), I used a wildcard and created a temp table to house the numbers.
I then have a while loop check for these individually through the database and put them in a third table.
I have read that cursor type commands are not efficient and there are generally better ways to solve such problems in SQL Server but my SQL knowledge is minimal at best and I don't even know where to start.
The query runs as is and returns exactly what I want it to, but when I ramp up the number of records, it increases the execution time linearly which is not sustainable if I want to search for say 1000 phone numbers.
Below is a snippet of my while code. How can I replace this with something more efficient? Please let me know if I should include additional information.
while @count_ < 77
Begin
Select @record = (select number
from @phoneNumbers
where Id_ = @count_)
INSERT @updatesFinal
SELECT
updates.[rowno], cust.no_, [empl],
[emplbr], [time_], [super], [column_],
[tablename], [urowno], [entered],
[new], [old], [seqno_updatesix]
FROM
[db1].[dbo].[updates]
INNER JOIN
db1.dbo.addr ON db1.rowno = updates.urowno
INNER JOIN
db1.dbo.cust ON cust.rowno = addr.rowno_custaddr_cust
WHERE
updates.column_ LIKE ('phone%')
AND old LIKE @record
SET @count_ = @count_ + 1
END