sql query - not contain

I want to query and get only itemno that does not starts with '*' (like *100037-000), and RCD  not 'y'  . This column is char(25).  It still return * itemno in front.
     
     SELECT ITEMNO FROM table_1 WHERE rcd not like ('*%') or rcd is not null or rcd <> 'n'
     
     select distinct(rcd) from tables_1
     results : Y, N, NULL
VBdotnet2005Asked:
Who is Participating?
 
nemws1Database AdministratorCommented:
Just need to re-arrange your logic a little bit:

SELECT ITEMNO
FROM table_1
WHERE NOT (
    rcd LIKE '*%'
        OR rcd IS NULL
        OR rcd = 'n'
)

Open in new window

0
 
Aneesh RetnakaranDatabase AdministratorCommented:
you need a 'AND' instead of OR.
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Hmm...  Working for me in SQL 2012..
CREATE TABLE #tmp (val varchar(10))
INSERT INTO #tmp (val) VALUES ('*abc'), ('123'), ('Bob'), ('wackadoo')

SELECT * FROM #tmp WHERE val NOT LIKE '*%'
SELECT * FROM #tmp WHERE LEFT(val, 1) <> '*'

Open in new window

>RCD  not 'y'
>WHERE .. rcd <> 'n'
Perhaps you meant WHERE .. rcd <> 'Y'?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.