Mombu the Microsoft Forum sponsored links

Go Back   Mombu the Microsoft Forum > Microsoft > WHERE criteria
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 10th July 05:19
darren
External User
 
Posts: 1
Default WHERE criteria



I am trying to outpu some records using WHERE. I want
only records where employee contains name1, name2, name3,
name4, name5, name6 AND approved = No. I can get either
all records where approved = No or all records where
employee contains name1...., but not both. Here is my
query:


WHERE (approved = '%No%') AND (employee LIKE '%name1%' OR
employee LIKE '%name2%' OR employee LIKE '%name3%' OR
employee LIKE '%name4%' OR employee LIKE '%name5%')

ORDER BY employee ASC, period_ending DESC


Thanks for the help!
Darren
  Reply With Quote


  sponsored links


2 10th July 05:19
rohtash kapoor
External User
 
Posts: 1
Default WHERE criteria



Darren:

I have found what's wrong with your query.

You are doing this:
approved = '%No%'

Please change that to:
approved LIKE '%No%'

---
Rohtash Kapoor
http://www.sqlmantra.com
  Reply With Quote
3 10th July 05:19
vishal parkar
External User
 
Posts: 1
Default WHERE criteria


hi Darren,

Change where clause like this:

WHERE (approved = 'No') AND (employee LIKE '%name1%' OR
employee LIKE '%name2%' OR employee LIKE '%name3%' OR
employee LIKE '%name4%' OR employee LIKE '%name5%')

Basically "=" operator will check the exact value and there won't be any
wildcard checks. hence the where clause that you are evaluating is looking for
exact match for column "approved" with the value of "%No%"

-- Vishal
  Reply With Quote
4 10th July 05:19
rohtash kapoor
External User
 
Posts: 1
Default WHERE criteria


Vishal Sahib, I think Darren wants to use '%No%' because I think he believe
there might be some white spaces in the beginning or end of the string
entered in Approved field. So if there is one or more spaces before the
word NO then = operator will not work.

The other way is:

LTRIM(RTRIM(approved)) = 'No'

What do you think?

---
Rohtash Kapoor
http://www.sqlmantra.com
  Reply With Quote
5 10th July 05:19
vishal parkar
External User
 
Posts: 1
Default WHERE criteria


hi,


Im sticking to what he is saying in above statement. If he is looking for what
you are saying then your solution will work.

-- Vishal
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666