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 2000 Forums
 Transact-SQL (2000)
 Problem with 'in' function :(

Author  Topic 

FruitBatInShades
Yak Posting Veteran

51 Posts

Posted - 2006-08-07 : 09:34:14
I am trying to filter out all itemnames that begin with a letter using this statement:-

SELECT UniqueID,'(' + Left(ItemName,1) +')' + ItemName AS ItemName FROM DirectoryItems WHERE Left(ItemName,1) not in('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwyxz')


The brackets are to prove that ItemName starts with a letter! Any idea why this would be return all rows?

nr
SQLTeam MVY

12543 Posts

Posted - 2006-08-07 : 09:56:12
SELECT UniqueID,'(' + Left(ItemName,1) +')' + ItemName AS ItemName
FROM DirectoryItems
WHERE Left(ItemName,1) not in('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwyxz')
is the same as
WHERE Left(ItemName,1) <> 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwyxz'
(you only have one string for the in clause)
it should be
WHERE Left(ItemName,1) not in('A','B','C',....')

it's easier to
WHERE Left(ItemName,1) like ('[^A-Za-z]%')
WHERE Left(ItemName,1) not like ('[A-Za-z]%')



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-08-07 : 10:12:15
Is left necessary?

WHERE ItemName like '[^A-Za-z]%'
WHERE ItemName not like '[A-Za-z]%'

Madhivanan

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

- Advertisement -