Solved

sql where  not like from other table

Posted on 2013-05-24
8
425 Views
Last Modified: 2013-05-26
I have 2 tables. I table with alot of data/columns and 1 table with 1 column exclusions.
i need a select statement that will show tableA where columnA is NOT LIKE '%tableB.text%"
AND tableA.columnB is NOT LIKE '%tableB.text%'

The closest I got to work is this which works as an exact match. How can I adjust this to show like with %% on both sides
select * from errorlogs
where errorlogs.filename not in
(select exclusion.text from exclusion)
and errorlogs.ip not in
(select exclusion.text from exclusion)

Open in new window

0
Comment
Question by:rivkamak
  • 3
  • 3
  • 2
8 Comments
 
LVL 34

Expert Comment

by:Brian Crowe
ID: 39195006
There may be a better way to do this with a function and CROSS APPLY but...

Also I'm assuming you have a unique identifier of some kind in errorlogs which I am referring to as ErrorLogID

SELECT errorlogs.*
FROM errorlogs
WHERE ErrorLogID NOT IN (
SELECT DISTINCT errorlogs.ErrorLogID
FROM errorlogs
CROSS JOIN exclusion
WHERE errorlogs .filename LIKE '%' + exclusion.text + '%')
0
 

Author Comment

by:rivkamak
ID: 39195018
That didn't work. I didn't get anything back
0
 
LVL 34

Expert Comment

by:Brian Crowe
ID: 39195027
Please post your table creation scripts for errorlogs and exclusions so I can play with it.
0
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 39195270
SELECT el.*
FROM dbo.errorlogs el
INNER JOIN dbo.exclusion ex ON
    el.ColumnA NOT LIKE '%' + ex.text + '%' AND
    el.columnB NOT LIKE '%' + ex.text + '%'
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 34

Expert Comment

by:Brian Crowe
ID: 39195377
I don't think that will work because you will actually get duplicate errorlog records for each exclusion entry that doesn't match.  As I understand it each errorlog record needs to be compared against eachexclusion entry and only included in the resultset if there is NO match found.
0
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 39195467
DOH, now that I see more of the q, you're probably right.  I went by only part of the original q.
0
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 500 total points
ID: 39195475
SELECT el.*
FROM dbo.errorlogs el
WHERE
    NOT EXISTS(
        SELECT 1
        FROM dbo.exclusion ex
        WHERE
            el.filename LIKE '%' + ex.text + '%' OR
            el.ip LIKE '%' + ex.text + '%'
    )
0
 

Author Closing Comment

by:rivkamak
ID: 39198429
Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now