Solved

SQL syntax correction

Posted on 2004-10-03
1
457 Views
Last Modified: 2008-03-10
I have this sql statement which supposed goal is to select items based on the description field only if they do not have
the word 'Not in" or  "Discontinued" in the beginning of the description field; s in

" Not in the list..." or "Discontinued item..." and so forth

SELECT Publisher,Book,Descrip,Cost, List,pubid,RowLastUpDtByOp,RowLastUpdtDtTi from Books where pubid = '276 ' and(descrip not like 'Not%' or descrip not like 'Discontinued %') order by id

For some reason I still get those data that has 'Not in" or "Discontinued' in the resultset.
Where am I making the mistakes?

0
Comment
Question by:zachvaldez
1 Comment
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 125 total points
Comment Utility
Just change your "or" to "and":

SELECT Publisher,Book,Descrip,Cost, List,pubid,RowLastUpDtByOp,RowLastUpdtDtTi
FROM Books
WHERE pubid = '276 ' AND descrip not like 'Not%' AND descrip not like 'Discontinued %'
ORDER BY id
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now