Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 not like function

Author  Topic 

ntn104
Posting Yak Master

175 Posts

Posted - 2011-08-09 : 16:42:28
I want to exclude some of name that may ending with 'LLC' OR 'CORP', 'CORPORATION', 'INC'. I used the following, but it does not take all out....please review my statement and give me input on this...THANKS,

where (name not like '% LLC'
OR NAME NOT LIKE '%LLC%'
OR NAME NOT LIKE 'CORPORATION %'
OR NAME NOT LIKE '% CORP %'
OR NAME NOT LIKE '% INC'
OR NAME NOT LIKE 'INC %'
OR NAME NOT LIKE '% INC%')

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-08-09 : 17:32:48
Change all the ORs to AND.
Go to Top of Page

ntn104
Posting Yak Master

175 Posts

Posted - 2011-08-10 : 07:09:12
I changed to "AND" but still not working properly....

quote:
Originally posted by robvolk

Change all the ORs to AND.

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-08-10 : 07:29:01
Post some sample data with expected result

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ntn104
Posting Yak Master

175 Posts

Posted - 2011-08-10 : 07:35:55
Below are example of name for column: NAME

DARRELL S OVERHEAD DOOR SERVICE LLC
CWM REMODELING LLC
CURRAN ACCOUNTING SERVICES LLC
CMP MARINE SALES LLC
CEYLAN PAINTING LLC
BERKE YOUNG INTERNATIONAL LLC
ARNISDALE INV LLC
4WARD THINK CONSULTING LLC
WINSTON & ALLIED LLC
TORRES ROOFING AND SIDING LLC
STEVENS & JOHNSON LLC
STEVE PAUL LLC
SANDERSONS PAINTING LLC
S & S STUDENT HOUSING LLC
ROBERT JENSEN RESTORATION LLC
RNOBLE LLC
WARFIELD PLUMBING & HEATING INC
PHILIP M COHN
REINHOLD F TRAUB
SEAN MENDEZ CATLIN
WILLIAM B BLOOM
SCOTT E LANDRY
HOLSBERG, WILLIAM A

And I expect to see only below for result. Thanks,
PHILIP M COHN
REINHOLD F TRAUB
SEAN MENDEZ CATLIN
WILLIAM B BLOOM
SCOTT E LANDRY
HOLSBERG, WILLIAM A

quote:
Originally posted by madhivanan

Post some sample data with expected result

Madhivanan

Failing to plan is Planning to fail

Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2011-08-10 : 10:28:55
Ugly, works, MUST be a better way...

create table #yak (YakName varchar(50))

insert into #yak (YakName)
select
'DARRELL S OVERHEAD DOOR SERVICE LLC'
union all select 'CWM REMODELING LLC'
union all select 'CURRAN ACCOUNTING SERVICES LLC'
union all select 'CMP MARINE SALES LLC'
union all select 'CEYLAN PAINTING LLC'
union all select 'BERKE YOUNG INTERNATIONAL LLC'
union all select 'ARNISDALE INV LLC'
union all select '4WARD THINK CONSULTING LLC'
union all select 'WINSTON & ALLIED CORP'
union all select 'TORRES ROOFING AND SIDING LLC'
union all select 'STEVENS & JOHNSON LLC'
union all select 'STEVE PAUL LLC'
union all select 'SANDERSONS PAINTING LLC'
union all select 'S & S STUDENT HOUSING LLC'
union all select 'ROBERT JENSEN RESTORATION CORPORATION'
union all select 'RNOBLE LLC'
union all select 'WARFIELD PLUMBING & HEATING INC'
union all select 'PHILIP M COHN'
union all select 'REINHOLD F TRAUB'
union all select 'SEAN MENDEZ CATLIN'
union all select 'WILLIAM B BLOOM'
union all select 'SCOTT E LANDRY'
union all select 'HOLSBERG, WILLIAM A '


select
yakname
from
#yak
WHERE
RIGHT(LTRIM(rtrim(YakName)),charindex (' ', reverse(LTRIM(rtrim(YakName))),1) -1) NOT LIKE '%LLC%'
AND RIGHT(LTRIM(rtrim(YakName)),charindex (' ', reverse(LTRIM(rtrim(YakName))),1) -1) NOT LIKE '%CORP%'
AND RIGHT(LTRIM(rtrim(YakName)),charindex (' ', reverse(LTRIM(rtrim(YakName))),1) -1) NOT LIKE '%INC%'

drop table #yak



http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

theboyholty
Posting Yak Master

226 Posts

Posted - 2011-08-10 : 10:52:10
I ran the following code:
CREATE TABLE #Test (Name VARCHAR(255))
INSERT INTO #Test
SELECT 'DARRELL S OVERHEAD DOOR SERVICE LLC' UNION
SELECT 'CWM REMODELING LLC' UNION
SELECT 'CURRAN ACCOUNTING SERVICES LLC' UNION
SELECT 'CMP MARINE SALES LLC ' UNION
SELECT 'CEYLAN PAINTING LLC' UNION
SELECT 'BERKE YOUNG INTERNATIONAL LLC ' UNION
SELECT 'ARNISDALE INV LLC' UNION
SELECT '4WARD THINK CONSULTING LLC' UNION
SELECT 'WINSTON & ALLIED LLC' UNION
SELECT 'TORRES ROOFING AND SIDING LLC ' UNION
SELECT 'STEVENS & JOHNSON LLC' UNION
SELECT 'STEVE PAUL LLC' UNION
SELECT 'SANDERSONS PAINTING LLC' UNION
SELECT 'S & S STUDENT HOUSING LLC ' UNION
SELECT 'ROBERT JENSEN RESTORATION LLC' UNION
SELECT 'RNOBLE LLC ' UNION
SELECT 'WARFIELD PLUMBING & HEATING INC ' UNION
SELECT 'PHILIP M COHN ' UNION
SELECT 'REINHOLD F TRAUB ' UNION
SELECT 'SEAN MENDEZ CATLIN ' UNION
SELECT 'WILLIAM B BLOOM ' UNION
SELECT 'SCOTT E LANDRY ' UNION
SELECT 'HOLSBERG, WILLIAM A '

SELECT *
FROM #Test
where (name not like '% LLC'
and NAME NOT LIKE '%LLC%'
and NAME NOT LIKE 'CORPORATION %'
and NAME NOT LIKE '% CORP %'
and NAME NOT LIKE '% INC'
and NAME NOT LIKE 'INC %'
and NAME NOT LIKE '% INC%')


and ended up with the following result:
HOLSBERG, WILLIAM A
PHILIP M COHN
REINHOLD F TRAUB
SCOTT E LANDRY
SEAN MENDEZ CATLIN
WILLIAM B BLOOM

Robvolk's advice was correct, there must be something else going on that's causing it to not work properly.

What result are you actually getting?

---------------------------------------------------------------------------------
http://www.mannyroadend.co.uk A Bury FC supporters website and forum
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-08-10 : 12:25:47
One possible issue is that some of LIKE claues have spaces after the string and before the wild-card. So '% CORP %' WIll not match to 'Foo Corp' becuase 'foo corp' doesn't have a space at the end.
Go to Top of Page
   

- Advertisement -