Microsoft SQL Server 2005
--
Questions
--
Followers
Top Experts
I have a query below and i need to optimize and generalize it .
The like parameters are subject to change as per the user select the domain. Please help
Senz
Select distinct SourceDomainName from ITM_Alerts where 
SourceDomainName like '%ABC%' and SourceDomainName like '%DEF%' and SourceDomainName like '%HIJ%'
and SourceDomainName like '%KLO%'
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
The query fetches around 100 rows as all the domains have sub domains, and in the current senario its taking much time.
LIKE '%abc%def%ghi%jkl%'
Or something to that effect.
Select distinct SourceDomainName from ITM_Alerts where
SourceDomainName like '%ABC%DEF%HIJ%KLO%'
this is not possible as the like parameters are diffrent values and not part of a single string.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
select distinct SourceDomainName
from ITM_Alerts
where SourceDomainName like '%ABC%'
  and SourceDomainName like '%DEF%'
  and SourceDomainName like '%HIJ%'
  and SourceDomainName like '%KLO%'
Should probably be:
select distinct SourceDomainName
from ITM_Alerts
where SourceDomainName like '%ABC%'
   or SourceDomainName like '%DEF%'
   or SourceDomainName like '%HIJ%'
   or SourceDomainName like '%KLO%'
You may not need this unless you have duplicates in the data. Just noting in case you were doing this in case a domain matches multiple.
from ITM_Alerts
where SourceDomainName like '%CSC%'
   or SourceDomainName like '%BHP%'
   or SourceDomainName like '%IMM%'
   or SourceDomainName like '%RIO%'
this will also return the same result , but can we optimize the time

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Microsoft SQL Server 2005
--
Questions
--
Followers
Top Experts
Microsoft SQL Server 2005 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. It includes support for managing XML data and allows a database server to be exposed over web services using Tabular Data Stream (TDS) packets encapsulated within SOAP (protocol) requests.