Solved

sql where  not like from other table

Posted on 2013-05-24
8
423 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mySql Syntax 7 27
Managing SQL log files, SQL Server 2014 6 55
SQL query 4 27
Very interesting Access query problem. 13 34
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

708 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

15 Experts available now in Live!

Get 1:1 Help Now