Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In Sql My Query is like ..
SQL
SELECT *
FROM ProductMaster
WHERE CatalogId = '1007'
	AND SubCode LIKE '%A%'
	OR SubCode LIKE '%B%'
	AND EntryUser = 'Green'
	AND (
	 ProductMasterId != '1000')


In Output i do not want the Row that has '1000' as ProductMasterId but still this row is coming in output so any solution for this
Posted
Updated 4-Sep-13 6:02am
v3

Looks like a problem with the OR condition. Try:

SQL
SELECT *
FROM ProductMaster
WHERE CatalogId = '1007'
    AND (SubCode LIKE '%A%'
    OR SubCode LIKE '%B%')
    AND EntryUser = 'Green'
    AND (
     ProductMasterId != '1000')
 
Share this answer
 
Comments
Manfred Rudolf Bihy 4-Sep-13 12:07pm    
It most definitely is. I don't know why this was down voted.
Have my 5! :)
scottgp 4-Sep-13 12:53pm    
No idea, but thanks. :-)
"Not equal" is "<>" in SQL.

Try changing it to that and see what happens.

This should be your query:
SELECT *
FROM ProductMaster
WHERE CatalogId = 1007 
     AND SubCode LIKE '%A%' 
     OR SubCode LIKE '%B%' 
     AND EntryUser = 'Green'
     AND ProductMasterId <> 1000


This is proper syntax and will work provided your logic is correct. Try removing one section of your where clause at a time and see where that gets you.
 
Share this answer
 
v2
Comments
Member 10252567 4-Sep-13 10:29am    
Same Error no change
Richard C Bishop 4-Sep-13 10:31am    
Is productmasterid a varchar or an int?
Member 10252567 4-Sep-13 10:33am    
int
Richard C Bishop 4-Sep-13 10:34am    
Ok, remove the single quotes from around 1000.
Member 10252567 4-Sep-13 10:44am    
still i m getting same output i think may be error in another condition ???
Hi you can try this query

SQL
SELECT * from( select * 
FROM ProductMaster
WHERE (CatalogId = 1007 AND (SubCode LIKE '%A%' OR SubCode LIKE '%B%' )AND EntryUser = 'Green')) as x where  x.ProductMasterId <> 1000


Regards,
Mubin
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900