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
 General SQL Server Forums
 New to SQL Server Programming
 Using NOT LIKE with multiple values

Author  Topic 

sonjan
Starting Member

22 Posts

Posted - 2013-01-17 : 19:50:02
Hi

I am trying to write a script to retrieve all fuel transactions that are not in multiple locations.

Example:

select * from fueltrans with (nolock) where location not like ('%capalaba%','%ormiston%','%thorneside%')

Appreciate feedback.
Thanks
Sonja

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2013-01-17 : 19:59:24
Depends on whether you want not to have all 3 or either one
.If either one you can change it to OR

Select * from fueltrans with (nolock) Where (location not like '%capalaba%') AND (location not like '%ormiston%') AND (location not like '%thorneside%')
Go to Top of Page

sonjan
Starting Member

22 Posts

Posted - 2013-01-17 : 20:02:53
Thank you, it was to include all suburbs listed.
Sonja
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-17 : 22:34:25
[code]
select f.* from fueltrans f
join (select 'capalaba' as cat
union all
select 'ormiston'
union all
select 'thorneside'
)t
on f.location not like '%' + t.cat + '%'
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2013-01-18 : 12:55:47
Using NOT LIKE will force a scan through all possibilities.There are probably more efficient ways.
You're using NOLOCK in your initial query. If you're also issuing updates , inserts this could cause dirty reads. Is that intended behaviour?

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-18 : 13:17:39
see

http://visakhm.blogspot.in/2010/02/avoiding-deadlocks-using-new.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2013-01-19 : 03:27:48
keep in mind if you're to implement READ_COMMITTED_SNAPSHOT isolation level there is added pressure on the tempdb. Tempdb can potentially be a serious bottleneck.Of course , it is possible to tune the tempdb , such as the type of storage , file numbers etc
http://www.sqlserver-dba.com/2011/04/tempdb-performance-and-strategy-checklist.html

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page
   

- Advertisement -