Solved

sql where  not like from other table

Posted on 2013-05-24
8
426 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 69

Expert Comment

by:Scott Pletcher
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
 
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:Scott Pletcher
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:
Scott Pletcher 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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 set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

786 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